forked from lfkdsk/PracticeCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubProtoTest.js
More file actions
44 lines (31 loc) · 805 Bytes
/
Copy pathsubProtoTest.js
File metadata and controls
44 lines (31 loc) · 805 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
/**
* Created by liufengkai on 16/6/26.
*/
function Student(props) {
this.name = props.name;
}
Student.prototype.hello = function () {
console.log(this.name + " is running!!!");
};
function PrimaryStudent(props) {
Student.call(this, props);
this.grade = props.grade || 1;
}
function F() {
}
F.prototype = Student.prototype;
PrimaryStudent.prototype = new F();
PrimaryStudent.prototype.constructor = PrimaryStudent;
PrimaryStudent.getGrade = function () {
return this.grade;
};
function inherits(Child, Parent) {
var F = function () {
};
F.prototype = Parent.prototype;
Child.prototype = new F();
Child.prototype.constructor = Child;
}
var smallMing = new PrimaryStudent({name: 'xiaoming', grade: 222});
smallMing.hello();
console.log(smallMing.name);