Skip to content
Advertisement

Prototypal Inheritance: where to find the message property of Error instance?

JavaScript

The above makes absolute sense; message is a property of x instance of Error

JavaScript

The question is: Where does message exist if neither in the y instance itself nor in the prototype chain?

Advertisement

Answer

Object.keys will only include own and enumerable properties. Now it happens that an Error object inherits a non-enumerable property message, so you don’t see it with Object.keys, but it certainly is there.

You can list also non-enumerable properties with Object.getOwnPropertyNames:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement