**為何要了解this的運作?** 主流框架都會使用到this。 **this的指向** 與如何定義無關,只與調用方式有關,若前面有物件,this就會指向該物件 通常不會使用simple call的方式來調用this,因為可能會使結果不如預期(指向全域)。 **callback function的this** callback function的函式屬於simple call,因此大多指向全域,少部分會重新定義,因此盡可能不要在callback function內調用this。 **宣告變數的影響** var為全域變數,因此: 1. 箭頭函式往外層找若沒有定義函式 2. simple call的函式 3. callback function 以上三種情況,會找到以var定義的全域變數。 若使用const及let定義變數,則會找不到該變數,出現結果為undefined。
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up