JSの基礎 - 継承

1、実装の継承:プロトタイプチェーン
        関数extend1(){
          this.name =「ジョン・ドウ」。
        }
        関数extend2(){
          this.age 18を=。
        }
        extend2.prototype =新しいextend1(); // extend2は、属性のextend1を継承しました
        VAR _extend1 =新しいextend2();
        console.log(_extend1.name); //ジョー・スミス
        console.log(_extend1.age); // 18
  関数extend3(){
          this.address =「重慶」。
        }
        extend3.prototype =新しいextend2(); // extend3継承extend1とextend2
        VAR _extend2 =新しいextend3();
        console.log(_extend2.name); //ジョー・スミス
        console.log(_extend2.age); // 18
        console.log(_extend2.address); //重慶
2、継承の組み合わせ
  機能グループ1(年齢){
          this.name = [ "リンダ"、 'ボブ'、 'ルーシー'、 'アンナ']。
          this.age 25を=。
        }
        Group1.prototype.run =関数(){
          this.name +を返す '' + this.age。
        }
        機能グループ2(年齢){
          Group1.call(この、年齢); //オブジェクトマスカレード
        }
        Group2.prototype =新しいグループ1(); //プロトタイプチェーンの継承
        VaRの_group1 =新しいグループ2(20)。
        console.log(_group1.run())。

おすすめ

転載: www.cnblogs.com/LindaBlog/p/10984189.html
おすすめ