老版继承
call ()
function User(name, pass){
this.name=name;
this.pass=pass;
}
User.prototype.showName=function (){
alert(this.name);
};
User.prototype.showPass=function (){
alert(this.pass);
};
//继承
function VipUser(name, pass, level){
User.call(this, name, pass);
this.level=level;
}
VipUser.prototype=new User();
VipUser.prototype.constructor=VipUser;
VipUser.prototype.showLevel=function (){
alert(this.level);
};
var v1=new VipUser('blue', '123456', 3);
v1.showName();
v1.showPass();
v1.showLevel();
ES6继承
extends 继承
super 超类/父类
class User{
constructor(name, pass){
this.name=name;
this.pass=pass;
}
showName(){
alert(this.name);
}
showPass(){
alert(this.pass);
}
}
//继承
class VipUser extends User{
constructor(name, pass, level){
super(name, pass); //super(...args);
this.level=level;
}
showLevel(){
alert(this.level);
}
}
var v1=new VipUser('blue', '123456', 3);
v1.showName();
v1.showPass();
v1.showLevel();