Usage
const ExtendableError = ; { superm; // Optional - ExtendableError sets `name` to your class's name itself, // but minification, etc. can change that, so you may want to do it // explicitly. thisname = 'MyError'; }
extendable-error-class
has no dependencies.
Why
Because the following doesn't work as expected.
{ superm; }
How
The workaround is based on babel-plugin-transform-builtin-extend
and following code
const ExtendableError = { supermessage; thisname = thisconstructorname; thismessage = message; if typeof ErrorcaptureStackTrace === 'function' Error; else thisstack = messagestack; };
The code is already compiled with babel
and babel-plugin-transform-builtin-extend
. Therefore one is able to use this workaround without adding any dependency.
See http://stackoverflow.com/questions/31089801/extending-error-in-javascript-with-es6-syntax