-
Notifications
You must be signed in to change notification settings - Fork 0
/
check.js
84 lines (79 loc) · 2.14 KB
/
check.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
const kids = 3;
const proto = {
parents: 2,
play: () => 'played',
};
const obj = {};
obj['created'] = Object.create(proto);
obj['created_obj'] = Object.create(proto, {
kids: { value: kids },
});
obj['assigned'] = Object.assign(proto, { kids });
obj['created_assigned'] = Object.assign(
Object.create(proto),
{ kids }
);
[
'created',
'created_obj',
'assigned',
'created_assigned',
].forEach(key => {
const o = obj[key];
try {
console.log(`================ ${key}`);
console.log('__proto__:', o.__proto__);
console.log(
'hasOwnProperty(parents):',
o.hasOwnProperty('parents')
);
console.log(
'hasOwnProperty(play):',
o.hasOwnProperty('play')
);
console.log(
'hasOwnProperty(kids):',
o.hasOwnProperty('kids')
);
console.log(
'getPrototypeOf:',
Object.getPrototypeOf(o)
);
console.log('(Object):', o);
console.log('(play):', o.play());
console.log('(kids):', o.kids);
console.log('(parents):', o.parents);
} catch (err) {
console.error(err);
}
});
/*
* ================ created
* __proto__: { parents: 2, play: [Function: play], kids: 3 }
* hasOwnProperty(parents): false
* hasOwnProperty(play): false
* hasOwnProperty(kids): false
* getPrototypeOf: { parents: 2, play: [Function: play], kids: 3 }
* (Object): {}
* ================ created_obj
* __proto__: { parents: 2, play: [Function: play], kids: 3 }
* hasOwnProperty(parents): false
* hasOwnProperty(play): false
* hasOwnProperty(kids): true
* getPrototypeOf: { parents: 2, play: [Function: play], kids: 3 }
* (Object): {}
* ================ assigned
* __proto__: [Object: null prototype] {}
* hasOwnProperty(parents): true
* hasOwnProperty(play): true
* hasOwnProperty(kids): true
* getPrototypeOf: [Object: null prototype] {}
* (Object): { parents: 2, play: [Function: play], kids: 3 }
* ================ created_assigned
* __proto__: { parents: 2, play: [Function: play], kids: 3 }
* hasOwnProperty(parents): false
* hasOwnProperty(play): false
* hasOwnProperty(kids): true
* getPrototypeOf: { parents: 2, play: [Function: play], kids: 3 }
* (Object): { kids: 3 }
*/