-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass_extends.js
More file actions
57 lines (52 loc) · 954 Bytes
/
class_extends.js
File metadata and controls
57 lines (52 loc) · 954 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
/**
* js 继承
*/
function Parent() {
this.name = 'parent'
}
Parent.prototype.log = function() {
console.log('parent log')
}
function Child() {
this.age = 28
}
Child.prototype.eat = function() {
console.log('child eat')
}
function fn_extends(target, origin) {
function Fn() {}
Fn.prototype = origin.prototype
target.prototype = new Fn()
target.prototype.constructor = target
}
// extend
fn_extends(Child, Parent)
let child = new Child()
console.log(child)
//es6 extend
class P {
constructor() {
this.name = 'parent'
}
log() {
console.log('parent log')
}
static a() {
console.log('parent staic b')
}
}
class C extends P {
constructor() {
super()
this.age = 28
}
eat() {
console.log('child eat')
}
static b() {
console.log('child staic b')
}
}
c= new C()
console.log('函数:', C)
console.log('实例: ', c)