-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrototypeAndPrototypeInheritance.js
More file actions
64 lines (46 loc) · 1.63 KB
/
PrototypeAndPrototypeInheritance.js
File metadata and controls
64 lines (46 loc) · 1.63 KB
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
60
61
62
63
64
let arr=["swathi","raji","reddy"];
// here once we create arr its accessble to use all Array methods just becaus eof type array its allows to access all array methods
// variable name does not matter type matters
// if we see Array.prototype and arr.__proto__ gives same
let obj={
name:"swathi",
city:"khammam",
}
let obj2={
name:"swathi",
city:"khammam"
}
console.log();
//here also obj.__proto__ is same like Object.prototype
// soo Array.prototype is Fist in Chain
// Object.prototype
// null
// arr.__proto__
// arr.__proto__.__proto__=obj.__proto__
// rr.__proto__.__proto__.__proto__ =null se the chaining first arr then obj then its null
// here when evr we are creating a particulr arr or object javascript attaching a object to in in the form of __proto__ (woth all hidden function in it)
let obj3={
name:"swathi",
city:"khammam",
getName:function(){
console.log(this.name+" "+this.city);
}
}
let obj4={
name:"rajesh",
// city:"thummma"
}
console.log(obj3.__proto__);
console.log(obj4.__proto__);
console.log(obj3.getName());
// console.log(obj4.getName());//here it throws error obj4 does not have any function of getName
// so here prototypal inheritance came into PictureInPictureEvent
// seee magic
obj4.__proto__=obj3;
console.log(obj4.getName());//first it checks inthis obj4 if it does have any key which needs to render in fucnction then it goes to its parent
// in one of our previous practice we mentione dthat
//in bind polyfill
Function.prototype.myBind=function(){
}
// right here by attching this in every function in thisfile directly access the myBind
// like sample.myBind();