1

What is the relationship between Function.prototype and the Object instance?

function Person() {}
var obj = new Object();
console.dir(Person.prototype);
console.dir(obj);

the console result is: enter image description here

My question:

What happened behind while function Person() {} run? How the constructor function added to Person.prototype?

1
  • someFunction.prototype.constructor == someFunction. the result of calling that function is the default prototype for an instance made with that constructor. Commented Dec 31, 2016 at 3:32

1 Answer 1

2

This one can be answered by looking at the EMCAScript standard

First, look at the new keyword, documented here:

https://www.ecma-international.org/ecma-262/5.1/#sec-11.2.2

which in turn calls the internal [[Construct]] method, documented here:

https://www.ecma-international.org/ecma-262/5.1/#sec-13.2.2

Step 7: Set the [[Construct]] internal property of F as described in 13.2.2.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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.