-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay45SuperKeyword.html
59 lines (52 loc) · 1.26 KB
/
Day45SuperKeyword.html
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Day45</title>
</head>
<body>
<script>
// without super keyword
let animal={
name:'animal',
eat:function(){
console.log('name of eating one is',this.name)
}
}
let cat={
__proto__:animal,
eat(){
this.__proto__.eat.call(this);// error this keyword point this again again
}
}
let dog={
__proto__:cat,
eat(){
this.__proto__.eat.call(this);
}
}
// console.log(dog.eat());
// using super keyword
let animal1={
name:'animal',
eat:function(){
console.log('name of eating one is',this.name)
}
}
let cat1={
__proto__:animal1,
eat(){
super.eat(); //it will homeobject so this wont get confused
}
}
let dog1={
__proto__:cat1,
eat(){
super.eat();
}
}
console.log(dog1.eat());
</script>
</body>
</html>