Object.setPrototypeOf in js code example
Example 1: isPrototypeOf js
/"Checks if an object exists in another object's prototype chain."/
function Bird(name) {
this.name = name;
}
let duck = new Bird("Donald");
Bird.prototype.isPrototypeOf(duck);
Example 2: object setprototypeof
const user = { name: 'John' };
const arr = [ 1, 2, 3 ];
console.log('Original state');
console.log(user);
console.log(user[1]);
console.log(user.__proto__);
console.log(user.length);
Object.setPrototypeOf(user, arr);
console.log('Modified state');
console.log(user);
console.log(user[1]);
console.log(user.__proto__);
console.log(user.length);