forked from pluralsight/web-dev-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprototype_proto.js
47 lines (42 loc) · 1.19 KB
/
prototype_proto.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
// Creating instance
const instance = {
key: "Value",
__proto__: {
bar_prop: "bar prototype values",
__proto__: {
foo_prop: "foo prototype values",
// This can be omitted
__proto__: Object.prototype,
},
},
};
console.log(instance.foo_prop);
console.log(instance.bar_prop);
console.log(instance);
console.log(instance.__proto__);
console.log(instance.__proto__.__proto__);
console.log(instance.__proto__.__proto__.__proto__);
console.log(instance.__proto__.__proto__.__proto__.__proto__);
// Object
console.log(Object.prototype);
console.log(Object.prototype.__proto__);
console.log(Object.__proto__.__proto__.__proto__);
const obj = {};
console.log(obj.__proto__);
console.log(obj.__proto__.__proto__);
// Array prototype
const arr = [];
console.log(arr.__proto__);
console.log(arr.__proto__.__proto__);
console.log(arr.__proto__.__proto__.__proto__);
// Function prototype
const func = function () { };
console.log(func.__proto__);
console.log(func.__proto__.__proto__);
console.log(func.__proto__.__proto__.__proto__);
Function.prototype.myMethod = function (params) {
console.log(params);
}
func.myMethod('Hello');
const func2 = function (params) { }
func2.myMethod("world");