0

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

AntonBoarf
  • 1,239
  • 15
  • 31
  • 1
    No the constructor has no constructor property, the instance constructed with the constructor has (inherits it from the prototype) – Jonas Wilms Jun 12 '18 at 12:26
  • The Object() function does have a constructor property. But I don't know what it means – AntonBoarf Jun 12 '18 at 12:32
  • 1
    @JonasW. `Person.constructor` is inherited from `Function.prototype` as it is for all (constructor or not) functions – Bergi Jun 12 '18 at 12:43

2 Answers2

2

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.

Bergi
  • 630,263
  • 148
  • 957
  • 1,375
-1

constructor is a pointer towards the constructor function used to create a given value, all objects have one. For primitives it points towards the primitive constructor: Object, Number, Function and so on.

Doc: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/constructor

adz5A
  • 2,012
  • 9
  • 10