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

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

2 Answers 2

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.

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

Comments

-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

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.