亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

JS寄生組合繼承的疑問

JS寄生組合繼承的疑問

藍山帝景 2018-07-23 14:22:34
以下為JS寄生組合繼承的實現方式         function Super(b){             this.b = b;             this.fun = function(){}         }         Super.prototype.c = function(){console.log(1111)}         function Foo(a,b){             this.a = a;             Super.call(this,b);         }         var f = new Function();         f.prototype = Super.prototype;         Foo.prototype = new f();         var foo1 = new Foo(1,2);為什么不直接用以下方式,更簡潔而且能實現同樣的效果        function Super(b){             this.b = b;             this.fun = function(){}         }         Super.prototype.c = function(){console.log(1111)}         function Foo(a,b){             this.a = a;             Super.call(this,b);         }         Foo.prototype = Super.prototype;         var foo1 = new Foo(1,2);
查看完整描述

2 回答

?
月關寶盒

TA貢獻1772條經驗 獲得超5個贊

你是不是打錯了
Foo.prototype = Foo.prototype; Foo.prototype = Super.prototype;

Foo.prototype = Super.prototype;
Foo.prototype.c = function(){console.log(1111)}

Foo.prototype = new f();

還是不一樣吧


查看完整回答
反對 回復 2018-08-02
  • 2 回答
  • 0 關注
  • 649 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號