Search code examples
javascriptprototypeecmascript-5

JS : Difference between Object and Object.constructor


I don't understand the difference between Object and Object.constructor.

Let's take an example :

function Person() {}
var p = new Person();

Person is the function to create objects. So :

p instanceof Person //true
p.constructor // Person

Person is the constructor and I can create persons with new Person()

But Object is also a constructor ( I can create object with new Object()). So why Object has a constructor property since it's already a constructor itself ?

Thanks


Solution

  • So why does it have a constructor property since it's already a constructor itself?

    Because every constructor is a function, and those inherit their properties (like the call, apply and bind methods) from Function.prototype. Including the Function.prototype.constructor property, which points to Function.