showing results for - "object setprototypeof"
Abbi
30 Jul 2020
1/"Checks if an object exists in another object's prototype chain."/
2
3function Bird(name) {
4  this.name = name;
5}
6
7let duck = new Bird("Donald");
8
9Bird.prototype.isPrototypeOf(duck);
10// returns true
Joshua
12 Feb 2020
1const user = { name: 'John' };
2const arr = [ 1, 2, 3 ];
3
4console.log('Original state');
5console.log(user);            // { name: 'John' }
6console.log(user[1]);         // undefined
7console.log(user.__proto__);  // {}
8console.log(user.length);     // undefined
9
10Object.setPrototypeOf(user, arr); // добавляем прототип arr к user
11
12console.log('Modified state');
13console.log(user);            // Array { name: 'John' }
14console.log(user[1]);         // 2
15console.log(user.__proto__);  // [ 1, 2, 3 ]
16console.log(user.length);     // 3