0
function Test()
{
    this.name = 'test name';
}


console.log(Test.prototype.constructor.prototype.constructor);

I can't understand why is this a infinite chain of constructor - prototype?

I mean which are the purpose of this chain and why there is no end, the prototype has a constructor and the constructor has a prototype, its a loop-chain, and the constructor everytime is the same, can't imagine...

2 Answers 2

3

Well, every Function Object, by default has a .prototype property, which references the prototype object for this function (becomes only important if used as constructor).

And every prototype object by default has a reference to the constructor function, which of course, points back, to the constructor function (in your case Test()).

So, here we go

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

2 Comments

hmmm also the prototype.constructor.constructor.constructor. - works, incredible, still trying to understand...thanks
@Hello if you watch the .prototype.constructor.constructor carefully, you'll notice that this references the Function() basic constructor. Remember, a function is also an object in this language.
0

This is a desired behavior. The constructor property of a prototype refers to the object that owns the prototype (so it refers back to itself).

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.