-
-
Notifications
You must be signed in to change notification settings - Fork 112
Expand file tree
/
Copy pathproto-console.js
More file actions
66 lines (38 loc) · 885 Bytes
/
proto-console.js
File metadata and controls
66 lines (38 loc) · 885 Bytes
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
/*
* Author : OBKoro1
* Date : 2021-11-09 17:53:41
* LastEditors : OBKoro1
* LastEditTime : 2021-11-09 18:01:18
* description : 拼多多 原型链输出
*/
// pdd-20211109 拼多多 原型链输出
// 第一题
// 说出输出 并且解释为什么
function Foo() {
Foo.prototype.a = function () {
console.log(1)
}
this.a = function () {
console.log(2)
}
}
Foo.a = function () {
console.log(3)
}
Foo.prototype.a = function () {
console.log(4)
}
Foo.a()
let obj = new Foo()
obj.a()
Foo.prototype.a()
// 答案慎看
// 答案慎看
// 答案慎看
// 答案慎看
// 答案慎看
// 第一个输出 正确答案
// Foo.a() 3 // 直接找Foo这个函数对象上面的a
// let obj = new Foo()
// obj.a() 2 在this上找到a 不查找原型链
// Foo.prototype.a() 1 // 在构造函数实例化的时候 被重写了