LoginSignup
1
1

More than 5 years have passed since last update.

JSXのthisの覚え方

Posted at

ルールはたったひとつだけ

  • staticでないメンバー関数(コンストラクタ含む)のなかで this はそのメンバー関数を呼び出した時のレシーバとなる

関数内関数定義のなかだろうとイベントハンドラの中だろうと常にメンバー関数の this は一定です。static member functionのなかではthisは使えません。JS的にいうと、メソッドの先頭で var that = this; としてその後すべての this ではなく that を使うイメージ、といえばわかりやすいでしょうか。bind/apply/callといったものもないので this がそれ以外の何かになることはありません。

簡単でしょ?

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1