I see that the Error constructor is designed to be subclassable. I can
create simple error types like so:
class ZenError extends Error {}
let err = new ZenError("abc");
However, I would expect that:
err.name === "ZenError";
Such an expectation would be useful when determining how to deal with a
trapped error, and using such a technique would avoid the cross-realm and
cross-library-instance problems inherent with `instanceof`.
In any case, this is useless:
err.name === "Error";
I could, of course, do this manually:
class ZenError extends Error {
constructor(msg) { super(msg); this.name = this.constructor.name; }
}
Or even create an intermediate class which does this:
class CustomError extends Error {
constructor(msg) { super(msg); this.name = this.constructor.name; }
}
class ZenError extends CustomError { }
But I can't imaging ever *not* wanting to have the name property of the
error object equal the name of the constructor which created it.
Thoughts?
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss