function User(name,age){
    this.name=name;
    this.age=age;
}
User.prototype.show=function(){
    console.log(this.name,this.age);
}

function Admin(...args){
        //改变this的指向
    User.apply(this,args);
    Admin.prototype.showAdmin=function(){
        return "admin";
    }
}


Admin.prototype= Object.create(User.prototype);
let xj=new Admin("xj",18);
xj.show();

 

posted on 2022-01-29 19:46  weakup  阅读(65)  评论(0编辑  收藏  举报