<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>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                在JS中創建對象會習慣的使用 new 關鍵字和類構造函數(當然主要還是對象字面量),問題在于這樣會導致兩個類之間產生依賴性。 工廠模式就是一種有助于消除兩個類依賴性的模式。 - 簡單工廠模式:使用一個類(通常為單體)來生成實例。 - 復雜工廠模式:使用子類來決定一個成員變量應該是哪個具體的類的實例。 ## 簡單工廠模式 ```js let ComputerFactory = function(){} function MacComputer() {} function WinComputer() {} ComputerFactory.prototype = { makeProduct: function (model) { let product switch (model) { case "mac": product = new MacComputer() break case "win": product = new WinComputer() break default: break } return product; } } let factory = new ComputerFactory() let mac = factory.makeProduct('mac') let win = factory.makeProduct('win') ``` ## ES6 ```js class Computer { constructor () { this.product = 'Computer' } } class MacComputer extends Computer { constructor () { super() this.name = 'MacComputer' } } class WinComputer extends Computer { constructor () { super() this.name = 'WinComputer' } } function ComputerFactory (param) { let product = null switch (param) { case 'mac': product = new MacComputer() break case 'win': product = new WinComputer() break default: break } return product } let mac = ComputerFactory('mac') let win = ComputerFactory('win') ```
                  <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>

                              哎呀哎呀视频在线观看