Object.prototype returns empty object in Node
It is because the console.log() in node use util.inspect(), which uses Object.keys() on objects, and it returns enumerable properties only. And Object.prototype
contains non-enumerable properties, that is why it returns empty node.
Similar behavior can be observed in the below snippet, when we console.log(Object.prototype)
it logs an empty {}
;
console.log(Object.prototype);
But when we explicitly define an enumerable property in Object.prototype
it logs an object containing that property :
Object.defineProperty(Object.prototype, 'property1', { value: 42, enumerable : true});console.log(Object.prototype)
For Reference
By the way, you can use Object.getOwnPropertyNames
if you want to know or access these properties.
> Object.getOwnPropertyNames(Object.prototype)[ 'hasOwnProperty', 'constructor', 'toString', 'toLocaleString', 'valueOf', 'isPrototypeOf', 'propertyIsEnumerable', '__defineGetter__', '__lookupGetter__', '__defineSetter__', '__lookupSetter__', '__proto__' ]
It won't list other properties you might find in chrome dev console like scope or the value of promises. But it's good enough!