JavaScript: Object.setPrototypeOf

By Xah Lee. Date: . Last updated: .

New in JS2015.

Object.setPrototypeOf(obj, parent)
Set the parent of obj to parent. Return the changed obj.
let aa = {};
let bb = Object.create (aa);

// bb's parent is aa
console.log( Reflect.getPrototypeOf ( bb ) === aa ); // true

// now change parent
let cc = Object.setPrototypeOf ( bb, Array );

// return value is the new bb
console.log( cc === bb ); // true
console.log( Reflect.getPrototypeOf ( bb ) === Array ); // true

[see Prototype and Inheritance]

BUY
ΣJS
JavaScript in Depth

JS Obj Reference

Object Object

prototype