1

Every function object has __proto__ as their internal property. They also have prototype property. Since prototype is also an object it has a __proto__ property as well. My question is, do both the __proto__ property inside the prototype and in the function object point to Function.prototype?

Felix Kling
820k181 gold badges1.1k silver badges1.2k bronze badges
asked Jan 27, 2013 at 18:10
1
  • @Felix Kling haha i m relly weak in english . Commented Jan 27, 2013 at 18:27

4 Answers 4

1

No. A function's prototype property (i.e. SomeFunc.prototype) is a normal object and so its internal __proto__ property points to Object.prototype.

Simple way to test it:

function Foo() {};
console.log(Object.getPrototypeOf(Foo) === Object.getPrototypeOf(Foo.prototype));
// logs false
console.log(Object.getPrototypeOf(Foo) === Function.prototype);
// logs true
console.log(Object.getPrototypeOf(Foo.prototype) === Object.prototype);
// logs true

Only functions inherit from Function.prototype, no other objects.

answered Jan 27, 2013 at 18:17
Sign up to request clarification or add additional context in comments.

Comments

1

A function's attribute named prototype is a normal object which becomes the prototype for objects created when using that function as a constructor.

A function's actual prototype (accessible via __proto__) is an object called Function.prototype, which in order descends from Object.prototype.

Diagram

answered Jan 27, 2013 at 18:19

2 Comments

I've mspainted you a diagram.
+1 for the diagram. You might however add some other red arrows so we can see the "chains"
0

No.

The hidden __proto__ property, which shouldn't really be used directly by JS programmers is meant as the glue to tie an object to its prototype chain.

As such:

function x () {}
x.__proto__; // is a prototypical function, leading back to `Function.prototype`

However, prototype is just an object, which gets assigned to the __proto__ property of whatever you're creating with new, inside the function.

As it's just a regular object, __proto__ will eventually lead back to Object.prototype.

answered Jan 27, 2013 at 18:18

Comments

0

The __proto__ property points to the constructor from the function when you use the new operator.

If your constructor is a instanceof Function, all the properties and methods in the Function.proptotype object will be accessible by the instance, and will use the same as context.

Some browsers don't implement access to __proto__ object, so if you wan't to use, will lose compatibility.

More info in the MDN docs: https://developer.mozilla.org/en/docs/JavaScript/Reference/Global_Objects/Object/proto

answered Jan 27, 2013 at 18:19

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.