2

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?

CertainPerformance
374k55 gold badges354 silver badges359 bronze badges
asked Jul 4, 2018 at 2:25
2

1 Answer 1

2

__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.

answered Jul 4, 2018 at 2:30
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.