parent
86a953e088
commit
911913d740
|
|
@ -16,7 +16,6 @@ Student.prototype.hello = function(){ // 在构造函数的原型上定义方法
|
|||
}
|
||||
|
||||
|
||||
|
||||
//使用
|
||||
function createStudent(props) { // 对于new构造函数的封装,其优点:一是不需要new来调用,二是参数灵活
|
||||
return new Student(props || {}) // 通过new创建构造函数,并传入参数/属性
|
||||
|
|
@ -32,7 +31,6 @@ var xiaoming = createStudent({
|
|||
xiaoming.hello();
|
||||
|
||||
|
||||
|
||||
//继承
|
||||
function inherits(Child, Parent) { // 继承的封装方法 inherits(子类, 父类)
|
||||
var F = function () {}; // 定义空方法F
|
||||
|
|
@ -53,7 +51,6 @@ PrimaryStudent.prototype.getAge = function(){ //对子类添加方法
|
|||
}
|
||||
|
||||
|
||||
|
||||
//使用继承后的
|
||||
function createPrimaryStudent(props) { // 对于new构造函数的封装,其优点:一是不需要再new来调用,二是参数灵活
|
||||
return new PrimaryStudent(props || {}) // 通过new创建构造函数,并传入参数/属性
|
||||
|
|
@ -67,4 +64,3 @@ var xiaohong = createPrimaryStudent({
|
|||
xiaohong.hello();
|
||||
xiaohong.getAge();
|
||||
```
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue