In node.js calling console.log on an object that has an element called inspect prints undefined even though it still works as an object. I assume this is because node uses inspect internally to print stuff out.
var thingTwo = {
num: 1,
func: function (x) { 2; },
inspect: function (x) { "hi"; },
};
console.log(thingTwo); // undefined
To avoid this trap in the future is there a list of other words that break standard functionality?
Cool, this piqued my curiosity and indeed, there is an undocumented feature where an object can provide it’s own
inspectmethod. The relevant code in util.js:I.e., it’s only when
inspectexists and is a function that triggers the behavior.