this. この便利でハマりどころの多い変数 Array.forEach / map 系 のthisArg が安定しない。 this 変数の紹介 this 変数の例 apply , call window オブジェクト コールバック イベントハンドラ Array.forEach 個人的な結論 this はできるだけ避ける 調べたキッカケは Array.forEach arr = ["A","B","C"] arr.forEach( function ( x ) { console.log ( this ) } ) このthisとして this => [“A”,“B”,“C”] を期待したわけです。 でも、this = window arr = ["A","B","C"] arr.forEach( function ( x ) { console.log ( this ) } ) //=>
![ES/JavaScriptのthisとアロー演算子について知っておくべきこと - それマグで!](https://cdn-ak-scissors.b.st-hatena.com/image/square/69c23083e1bbc764cb00b7afde215d6ef4aec6c9/height=288;version=1;width=512/http%3A%2F%2Fcdn-ak.f.st-hatena.com%2Fimages%2Ffotolife%2Ft%2Ftakuya_1st%2F20160602%2F20160602152936.jpg)