原来的写法
function user(name,pass){
this.name = name;
this.pass = pass;
}
user.prototype.showName = function(){
alert(this.name);
}
user.prototype. showPass = function(){
alert(this.pass);
}
const choco = new user('choco895', 'pwd');
choco.showName();
新写法
class User{
constructor(name,pass){
this.name=name;
this.pass=pass;
}
showName=()=>{
alert(this.name);
}
showPass=()=>{
alert(this.pass);
}
}
let choco = new User("xixi","pwd");
choco.showName();
choco.showPass();
继承
class vipUser extends User {
constructor(name,pass,level) {
super(name, pass);
this.level = level;
}
showLevel =()=>{
alert(this.level)
}
}
let choco = new vipUser("xixi","pwd",'999');
choco.showName();
choco.showPass();
choco.showLevel();