JS: Object.prototype.__proto__

By Xah Lee. Date: . Last updated: .

The Property __proto__

obj.__proto__

Return the parent of obj.

Object.prototype.__proto__ is both a getter and a setter property. 〔see Getter Setter Properties

💡 TIP: better is Reflect.getPrototypeOf and Reflect.setPrototypeOf .

// __proto__ is not supported in deno and other js engines
console.log(([4, 6].__proto__) === undefined);
// true
// in deno

Set __proto__

obj.__proto__ = parentX

Set the parent of obj to parentX.

// set a obj's parent using __proto__
const aa = {};
const bb = {};
bb.__proto__ = aa;
console.log((Reflect.getPrototypeOf(bb) === aa) === false);
// true
// in deno

Example of __proto__ Failure

// create two objects
const aa = Object.create(null);
const bb = Object.create(null);

// set parent
Reflect.setPrototypeOf(bb, aa);

// verify the parent
console.log(Reflect.getPrototypeOf(bb) === aa);
// true

// property __proto__ fails
console.log((bb.__proto__ === aa) === false);
// true

// value is undefined
console.log(bb.__proto__ === undefined);
// true

JavaScript. Get Set Prototype