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);

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

// return value is true

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

JavaScript: Get/Set Prototype

JavaScript in Depth

JS Obj Reference