• 欢迎光临~

继承是原型的继承

开发技术 开发技术 2022-01-29 124次浏览

继承是原型的继承

 

 

function User(){}
User.prototype.name=function(){
    console.log("user.name");
}

function Admin(){}

//方式1
//Admin.prototype.__proto__==Object.prototype
console.log(Admin.prototype.__proto__==Object.prototype)
// Admin.prototype.__proto__=User.prototype;

//方式2
Admin.prototype=Object.create(User.prototype)
Admin.prototype.role=function(){
    console.log("admin.role");
}

function Member(){}

Member.prototype.role=function(){
    console.log("member.role");
}
let a=new Admin();
a.role();

继承是原型的继承

 

程序员灯塔
转载请注明原文链接:继承是原型的继承
喜欢 (0)
违法和不良信息举报电话:022-22558618 举报邮箱:dljd@tidljd.com