console.log(Function instanceof Object) // true
console.log(Function.__proto__ === Object.prototype) // false
console.log(Function.__proto__ == Function.prototype) // true
What's the technical explanation on why on line (2.) is "false" when Function is an instance of Object?
1 Answer 1
__proto__ references the immediate prototype object in the prototype chain. As you can see from #3, the prototype of Function is Function.prototype. Although a function is a type of object, Object.prototype is higher on the prototype chain - they're not the same, hence (Function.__proto__ === Object.prototype) is false:
console.log(Function.__proto__.__proto__ === Object.prototype);
// Same as:
console.log(Function.prototype.__proto__ === Object.prototype);
Function extends Object, as you can see.
Also, you might note that it's probably preferable to use getPrototypeOf. From MDN:
Warning: While Object.prototype.proto is supported today in most browsers, its existence and exact behavior has only been standardized in the ECMAScript 2015 specification as a legacy feature to ensure compatibility for web browsers. For better support, it is recommended that only Object.getPrototypeOf() be used instead.
Function.__proto__.__proto__ === Object.prototype, "Theinstanceofoperator tests whether the prototype property of a constructor appears anywhere in the prototype chain of an object."