This case works just fine:
class CustomError2015 extends Error {
constructor(message) {
super(message); // here the message is set correctly
console.log("Message: " + this.message);
}
}
throw new CustomError2015("ECMAScript 2015 class inheritance");
I expected that this one would work the same way, but it didn't:
function CustomError(message){
Error.call(this, message); // here the message IS NOT set
console.log("Message: " + this.message);
}
CustomError.prototype = Object.create(Error.prototype);
CustomError.prototype.constructor = CustomError;
throw new CustomError("CustomError function-like inheritance");
I'm wondering why? I there something wrong with my code or what?