LoginSignup
2
3

More than 5 years have passed since last update.

Javascriptのオブジェクト初期化で知らなかった構文

Posted at

meteorのチュートリアルをやっていると、次のようなコードに遭遇しました。

{
  'submit .new-task'(event) {
    // some code here
  },
}

オブジェクトリテラルなのは予想がつきますが、文字列のあとに無名関数みたいなものが続いていているパターンは初めて見ました。
オブジェクトイニシャライザーに関するMDNのドキュメントを読んでみたところ、次のコードと同値だということがわかりました。

{
  'submit .new-task': function(event) {
    // some code here
  },
}

慣れたら読みやすいのかもしれませんが、今の所違和感しかありません。

2
3
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
2
3