<thead id="rrjt3"></thead>
      <progress id="rrjt3"><dfn id="rrjt3"></dfn></progress>

      <em id="rrjt3"></em>

        <address id="rrjt3"><ins id="rrjt3"><dfn id="rrjt3"></dfn></ins></address>
          <i id="rrjt3"></i>

        請寫出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指向后,返回的是函數


        黄网站免费 <