タグ

ブックマーク / takuya-1st.hatenablog.jp (1)

  • ES/JavaScriptのthisとアロー演算子について知っておくべきこと - それマグで!

    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とアロー演算子について知っておくべきこと - それマグで!
    sakadon
    sakadon 2017/05/29
    文字列をみてHistoryをたどれば自明だが、、 => 継承っぽいだろ -> じゃないんだぞ(coffeescriptの挙動を参考にすれば理解しやすいかもしれない)まあthisが便利と思えないなら、JS触るのやめたらってのは同意
  • 1