繼承
標(biāo)簽:
JavaScript
function Parent(name) { this.name = name; } Parent.prototype.work = function () { console.log(this.name + " is working"); }; function Child(name, anotherName) { Parent.call(this, name); // 执行函数Parent(name) this.anotherName = anotherName; } Child.prototype = Object.create(Parent.prototype); // Object.create(Parent.prototype)的作用是:创建一个空对象,空对象的__proto__等于Parent.prototype Child.prototype.play = function () { console.log(this.anotherName + " is playing"); }; var child = new Child("Googler", "Googlex"); child.work(); child.play();
原型图
原型图.png
作者:Googler
链接:https://www.jianshu.com/p/657a761b06b5
點(diǎn)擊查看更多內(nèi)容
為 TA 點(diǎn)贊
評論
評論
共同學(xué)習(xí),寫下你的評論
評論加載中...
作者其他優(yōu)質(zhì)文章
正在加載中
感謝您的支持,我會繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進(jìn)行掃碼打賞哦