# this 100秒 一樣先看這個 https://www.youtube.com/watch?v=YOlr79NaAtQ https://www.youtube.com/watch?v=tpheRywjVQk ## 簡單描述 當前使用的物件(使用)(物件) 最簡單判斷 a.b() this指向a b() this指向全域 ## 箭頭涵式this簡單判斷 箭頭涵式this是看作用域 不是看誰使用他 所以往上找,找{}但記得function不算喔,記得去找當前使用的物件(使用)(物件) ## 執行callback callback不會影響到 this的結果 ex foreach是callback 所以外面要先存this ``` const vm = this; vm.data.foreach(function(item,index){ .... console.log(vm) }) ``` ## call apply bind call 改變this apply 改變this 參數array bind 宣告新的涵式變數 bind()裡面放this的  小注意 call在非嚴格模式下 null undefind會變成全域  ## 箭頭涵式 **箭頭涵式沒有自己的this** ``` var name = 'all' var auntie = { name:阿姨, callsomeone: ()=>{ console.log(this.name) } } ``` auntie.callsomeone() 會忽視auntie 去抓all ###### tags: `javaScript`
×
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