Maximus Maximus - 1 year ago 147
Javascript Question

MDN constructor property explanation confusion

I'm reading this article about

property and it states the following:

Returns a reference to the Object function that created the instance's

And they give an example:

function Tree(name) { = name;

var theTree = new Tree('Redwood');
console.log('theTree.constructor is ' + theTree.constructor);

Here the instance is
and its prototype is
, which is Object function, not
. What am I misunderstanding?

Answer Source

The prototype of an object is typically inherited from its constructor function:

function Tree() {} = function () {};

var theTree = new Tree();

theTree now has from its prototype chain. The function Tree initialised the object, and is also responsible for the contents of its prototype chain. That's why they express it as "the Object function that created the instance's prototype".

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download