Extending Error class fails
This doesn't work:
class TestError extends Error {
constructor(message) {
super(message);
}
}
const error = new TestError('test message');
console.log(error.message);
Output:
var TestError = (function (Error) {
function TestError(message) {
Error.call(this, message);
}
if ( Error ) TestError.__proto__ = Error;
TestError.prototype = Object.create( Error && Error.prototype );
TestError.prototype.constructor = TestError;
return TestError;
}(Error));
var error = new TestError('test message');
console.log(error.message);
I expect the string 'test message' to be printed to the console, but nothing shows up.
Extending the Error class doesn't seem to be business as usual, so I can imagine you don't want to fix this... I solve it myself by setting the message property explicitly in the TestError class.
Some information can be found here: http://stackoverflow.com/questions/1382107/whats-a-good-way-to-extend-error-in-javascript Most people seem to set the message property in the subclass by default, but it should not be necessary. Running the ES6 code in node works without, anyway.