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{
}

 

你可能感兴趣的:(前端,javascript)