JS: Object.prototype.__proto__

By Xah Lee. Date: .

Object.prototype.__proto__ is both a getter and a setter property. [see JS: Getter/Setter Properties]

obj.__proto__ → is equivalent to Object.getPrototypeOf ( obj )

[see JS: Object.getPrototypeOf]

obj.__proto__ = proto → is equivalent to Object.setPrototypeOf ( obj, proto )

[see JS: Object.setPrototypeOf]

Get Prototype Example

const arr = [4,6];

console.log (
 Object.getPrototypeOf (arr)  === arr.__proto__
); // true

console.log (
 Object.getPrototypeOf (arr)  === arr["__proto__"]
); // true

Set Prototype Example

const aa = [4,6];

function FF () { }

// set a object's parent
console.log(
    aa.__proto__ = FF
); // [Function: FF]

console.log (
    Object.getPrototypeOf ( aa ) === FF
 ); // true

Note: it's recommend you NEVER change a object's parent. Due to how JavaScript is implemented, changing a object's parent causes major slow down.

Reference

ECMAScript® 2016 Language Specification#sec-additional-properties-of-the-object.prototype-object

JS Object Property Topic

  1. JS: Property Overview
  2. JS: Property Key
  3. JS: Property Dot Notation / Bracket Notation
  4. JS: Create/Delete Property
  5. JS: Get Property, Set Property
  6. JS: Check Property Existence
  7. JS: Access Property
  8. JS: Property Attributes, writable, enumerable, configurable
  9. JS: Getter/Setter Properties
  10. JS: Property Descriptor

Object and Inheritance Topic

  1. JS: Object Overview
  2. JS: Object Type
  3. JS: Determine Type of Object
  4. JS: Object Literal Expression
  5. JS: Prototype and Inheritance
  6. JS: Create Object
  7. JS: Create Object with Parent X
  8. JS: Get/Set Prototype
  9. JS: Prevent Adding Property
  10. JS: Clone, Deep Copy Object/Array
  11. JS: Test Equality of Objects
  12. JS: Object Object
  13. JS: Object.prototype
Liket it? Put $5 at patreon.

Or, Buy JavaScript in Depth

If you have a question, put $5 at patreon and message me.