JavaScript: Reflect.setPrototypeOf

By Xah Lee. Date: . Last updated: .

New in JS2015.

Reflect.setPrototypeOf( obj, parent )
Sets the parent of obj to parent. If obj is not a object throw a TypeError exception. If parent is not a object nor null throw a TypeError exception.
const aa = {};
const bb = Object.create (aa);

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

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

// return value is true
console.log( cc ); // true

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

[see Prototype and Inheritance]

JS in Depth
XAH  BUY NOW

JS in Depth

JS Obj Ref

DOM


JS Obj Ref

Reflect