JavaScript原理——模拟继承

1.原型继承

function Parent(){}
function Child(){}
Child.prototype = new Parent();

2.构造函数继承

function Parent(){};
function Child(){
    Parent.call(this, argument);
}

3.原型+构造函数继承

function Parent(){};
function Child(){
    Parent.call(this, argument);
}
Child.prototype = new Parent();

4.class继承

class Person{
}
class Child extends Person{
}

猜你喜欢

转载自blog.csdn.net/baidu_38798835/article/details/108632103