-
Notifications
You must be signed in to change notification settings - Fork 7
/
prototype.ts
41 lines (30 loc) · 913 Bytes
/
prototype.ts
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
// * 只要理解了 ES 的继承中:
// * 继承类的 prototype 是基类的实例
// * 实例没有 prototype
// * 实例的 __proto__ 是类的 prototype
class Base {}
class Ext extends Base {}
const inst = new Ext();
console.log([
// @ts-ignore
inst.__proto__ === Object.getPrototypeOf(inst),
// @ts-ignore
inst.prototype === undefined,
Object.getPrototypeOf(inst) === Ext.prototype,
]);
console.log([
//
Object.getPrototypeOf(Ext.prototype) === Base.prototype,
]);
console.log([
Base.prototype.constructor === Base,
Ext.prototype.constructor === Ext,
Object.prototype.constructor === Object,
Function.prototype.constructor === Function,
]);
console.log([
// * 一等公民 一等公民
Object.getPrototypeOf(Object) === Function.prototype,
Object.getPrototypeOf(Function) === Function.prototype,
Object.getPrototypeOf(Function.prototype) === Object.prototype,
]);