-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprototypes.js
54 lines (47 loc) · 844 Bytes
/
prototypes.js
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
let pockets = {
money: 2000
};
let head = {
glasses: 1
};
let table = {
pen: 3
};
let bed = {
sheet: 1,
pillow: 2
};
pockets.__proto__=table;
bed.__proto__=table;
table.__proto__=head;
console.log(pockets.__proto__);
console.log(head.glasses);
//getting from head.glasses is faster than from pockets.glasses since glasses property is found within head.
//we use the Object.getPrototypeOf() to find the prototype
function Light(high, low) {
this.high=high;
this.low=low;
};
let today=new Light('high', 'low');
console.log(Object.getPrototypeOf(today));
//outputs.
const a=()=>{}
undefined
typeof a;
'function'
typeof A;
'undefined'
function B() {}
undefined
typeof B;
'function'
Object.getPrototypeOf(a);
[Function]
Object.getPrototypeOf(B);
[Function]
a.prototype;
undefined
B.prototype;
B {}
B.prototype;
B {}