# 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的 ![](https://i.imgur.com/rYXx2Ck.png) 小注意 call在非嚴格模式下 null undefind會變成全域 ![](https://i.imgur.com/7QNhvCs.png) ## 箭頭涵式 **箭頭涵式沒有自己的this** ``` var name = 'all' var auntie = { name:阿姨, callsomeone: ()=>{ console.log(this.name) } } ``` auntie.callsomeone() 會忽視auntie 去抓all ###### tags: `javaScript`