I tried doing some simple type checking for errors, and had the following code:
function isError(x) {
return Error.isPrototypeOf(x)
}
However, if I call the function with an instance of an error, I get false
, like so:
isError(new RangeError) // false
So I fired up node (well, io.js anyway), and did the following:
> Object.getPrototypeOf(Object.getPrototypeOf(new RangeError))
[Error]
In the end, if I do a check with instanceof
, it works, like so:
> (new RangeError) instanceof Error
true
So, what exactly is going on here?