tmd45 / training-javascript

My Training JavaScript
https://github.com/tmd45/training-typescript
0 stars 0 forks source link

`this` の指すもの #1

Open tmd45 opened 7 years ago

tmd45 commented 7 years ago

https://hatena.github.io/Hatena-Textbook-JavaScript/language/function.html#this-キーワード

a.foo.call({}); // false (this は {} を指す)

ふぁ?!

って思ったら続きにちゃんと書いてあった>ハマりどころ

call 関数のドキュメント。第一引数の thisArg なるほど http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call

apply 関数のドキュメント http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply

bind 関数のドキュメント http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind

tmd45 commented 7 years ago

(Fat) Arrow Function の this https://developer.mozilla.org/ja/docs/Web/JavaScript/Guide/Functions#Arrow_functions

アロー関数は関数を取り囲むコンテキストから this の値をキャプチャーする