<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                [TOC] > [參考代碼](http://www.ruanyifeng.com/blog/2010/05/object-oriented_javascript_encapsulation.html) ## 實例 ### demo1 ``` var cookie ={ name:'acas', setCookie:function () { alert("asd"); } } alert(cookie.name) alert(cookie.setCookie) ``` #### demo2 缺點:浪費內存 ``` function Cat(name,color){ this.name=name; this.color=color; this.func = function (param) { alert(this.name+param); } } var cat1 = new Cat('asd1',"aaa"); cat1.func("haha") ``` ## 面向對象 ### 通過原型鏈 ``` function Cat(name,color){ this.name=name; this.color=color; } Cat.prototype.func=function (parma) { alert(this.name+parma); } //實例化調用 var cat1 = new Cat('asd1',"aaa"); cat1.func("haha") //不實例化,直接調用 Cat.prototype.func("asd") ``` ### 構造函數的繼承 方法一:構造函數綁定 ``` function Animal(){ this.species = "動物"; } function Cat(name,color){ Animal.apply(this, arguments); this.name = name; this.color = color; } //實例化調用 var cat1 = new Cat('asd1',"aaa"); alert(cat1.species); ``` 方法二: prototype模式 ``` function Animal(){ this.species = "動物"; } function Cat(name,color){ this.name = name; this.color = color; } Cat.prototype = new Animal(); var cat1 = new Cat("大毛","黃色"); alert(cat1.species); // 動物 ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看