-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathprototype.js
More file actions
45 lines (40 loc) · 790 Bytes
/
Copy pathprototype.js
File metadata and controls
45 lines (40 loc) · 790 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const dragon = {
name: "Tanya",
fire: true,
fight() {
return 5;
},
sing() {
if (this.fire) {
return `I am ${this.name}, the breather of fire`;
}
},
};
const lizard = {
name: "Kiki",
fight() {
return 1;
},
};
lizard.__proto__ = dragon;
console.log(lizard.fire);
console.log(lizard.sing());
console.log(lizard.fight());
console.log(dragon.__proto__);
// dragon is a prototype of lizard
console.log(dragon.isPrototypeOf(lizard));
for (let prop in lizard) {
if (lizard.hasOwnProperty(prop)) {
console.log(`lizard: ${prop}`);
} else {
console.log(`dragon: ${prop}`);
}
}
for (let prop in lizard) {
// ES2022
if (Object.hasOwn(lizard, prop)) {
console.log(`lizard: ${prop}`);
} else {
console.log(`dragon: ${prop}`);
}
}