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

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                [TOC] # 作用 創建一個新的函數,在調用時設置`this`關鍵字為提供的值。并在調用新函數時,將給定參數列表作為原函數的參數序列的前若干項。 <br> <br> # 功能 * 綁定this * 柯里化 ~~~ function add(a, b, c) { var i = a+b+c; console.log(i); return i; } var func = add.bind(undefined, 100);//給add()傳了第一個參數a func(1, 2);//103,繼續傳入b和c var func2 = func.bind(undefined, 200);//給func2傳入第一個參數,也就是b,此前func已有參數a=100 func2(10);//310,繼續傳入c,100+200+10 ~~~ <br> <br> # 模擬 關鍵點 * 判斷 this 是否 Function * 維護原型關系,新返回的函數繼承原函數 * 新函數調用時,判斷是否為new調用,是則this指向當前this,否則指向bind調用時的第一個參數 * 新函數調用時,將bind調用時的參數與返回的函數func實際調用時的參數拼接 ~~~ Function.prototype.bind = function (oThis) { if (typeof this !== 'function') { // closest thing possible to the ECMAScript 5 // internal IsCallable function throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable'); } var aArgs = Array.prototype.slice.call(arguments, 1) // 函數調用的參數 var fToBind = this // 要調用的函數 var fNOP = function () { } // 空函數 var fBound = function () { // 直接調用func,this指向window // 使用new調用,this指向bind調用后的返回值,即fBound,其原型是foo return fToBind.apply(this instanceof fBound ? this : oThis, // 將bind調用時的參數與返回的函數func實際調用時的參數拼接 aArgs.concat(Array.prototype.slice.call(arguments))); }; // 維護原型關系 // 實現繼承,相當于 fBound.prototype = Object.create(this.Prototype) if (this.prototype) { // Function.prototype沒有prototype屬性 fNOP.prototype = this.prototype; } // 下行的代碼使fBound.prototype是fNOP的實例,因此 // 返回的fBound若作為new的構造函數,new生成的新對象作為this傳入fBound,新對象的__proto__就是fNOP的實例 fBound.prototype = new fNOP(); return fBound; }; ~~~
                  <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>

                              哎呀哎呀视频在线观看