The Object.setPrototypeOf(object, prototype) method

The Object.setPrototypeOf() method is just another way to assign the [[prototype]] property of an object, which we have just discussed. You can either use this method or directly work with the __proto__ property. However, working with a method is a cleaner and easier-to-read approach. Here is an example to demonstrate this:

let x = {x: 12};let y = {y: 13};Object.setPrototypeOf(y, x);console.log(y.x); //Output "12"console.log(y.y); //Output "13"

Get Learn ECMAScript - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.