javascript中的this綁定

2020-4-21    前端達(dá)人

his是一個關(guān)鍵字,表示執(zhí)行當(dāng)前函數(shù)的對象

  • this永遠(yuǎn)跟著當(dāng)前函數(shù)走,
  • 永遠(yuǎn)是一個對象,

  • 永遠(yuǎn)在函數(shù)執(zhí)行時才能確定。
  • 1. 默認(rèn)綁定:沒有明確被隸屬對象執(zhí)行的函數(shù),this指向window


function fn(){
    console.log(this);              //window
    console.log(typeof this);       //object
}
fn();

- 嚴(yán)格模式下,this指向undefiend

"use strict";
function fn(){
    console.log(this);              //undefined
}
fn();




分享本文至:

日歷

鏈接

個人資料

存檔