smrakib
smrakib

Reputation: 41

Is __proto__ is a property of an object instance or its a property of Object.prototype

I try to understand prototype and gain a clear understanding so fur. Which i do not understand is that, is __proto__ is a property of an object instance or its a property of Object.prototype which we can use from object instance . I know other aspect about prototype and prototype chain and only want to know specifically that who won __proto__ actually ? Is its owner is every object instance or Object constructor (which we have to call new) prototype ?

Upvotes: 0

Views: 57

Answers (1)

Andrei
Andrei

Reputation: 191

From MDN:

The __proto__ property of Object.prototype is an accessor property (a getter function and a setter function) that exposes the internal [[Prototype]] (either an object or null) of the object through which it is accessed.

const obj = {};
console.log(obj.hasOwnProperty('__proto__')); // false
console.log(Object.prototype.hasOwnProperty('__proto__')); // true

__proto__ is somewhat deprecated. It's better to use:

  1. create - create a new object, using an existing object as the prototype
  2. getPrototypeOf to get an object's prototype
  3. setPrototypeOf to set it's prototype

Upvotes: 1

Related Questions