<noframes id="7xbfr"><pre id="7xbfr"><output id="7xbfr"></output></pre>

      <big id="7xbfr"><font id="7xbfr"><listing id="7xbfr"></listing></font></big>
        <p id="7xbfr"></p>
        <menuitem id="7xbfr"></menuitem>

          <video id="7xbfr"><mark id="7xbfr"><listing id="7xbfr"></listing></mark></video>
            <form id="7xbfr"></form>

          <delect id="7xbfr"><var id="7xbfr"></var></delect>

          請寫出4種this指向的方式和改變this指向的方式

          時間:2021-07-30 10:03:14 類型:web前端
          字號:    

          一、this指向的4種方式:

          1、如果是一般函數,this指向全局對象window;


          2、在嚴格模式下"use strict",為undefined.


          3、對象的方法里調用,this指向調用該方法的對象.


          4、構造函數里的this,指向創建出來的實例.


          二. 改變this指向的方式

          以下屬于函數的方法

          改變this的指向并且執行調用函數

          .call(),  call(thisScope, arg1, arg2, arg3...)

          .apply(), apply(thisScope, [arg1, arg2, arg3...]);兩個參數

          而bind 改變this的指向,返回的是函數

          .bind()  bind(thisScope, arg1, arg2, arg3...)

          call,可以傳入多個參數,改變this指向后立刻調用函數

          apply,可以傳入數組

           bind改變this指向后,返回的是函數


          黄网站免费 <