LoginSignup
0
0

More than 5 years have passed since last update.

JSでとまどったやつ【WIP】

Posted at

おもに【ECMAScript6の新機能 - Qiita】の記事を読み進めるにあたって、自身が今まで曖昧に理解していたものをピックアップ。

今後も追記するかどうかはその時の気分とか余裕度によって。

{ [ 'prop_' + (() => 42)() ]: 42 }

計算結果をプロパティ名にできる。

const obj = { [ 'prop_' + (() => 42)() ]: 42 }
const obj.prop_42; // => 42

メソッド名にも使用できる。

const a = 'hello';
const obj = {
  [a]() {
    console.log('this is hello');
  }
};
obj.hello(); // => 'this is hello'

{ somthing }

変数名とkey名が一緒なら省略可能。

const something = 'hello';
const obj = {something };
obj.something; // => 'hello'

[...someArray]

スプレッド演算子。
関数の引数で使ったら配列で受けるやつ。
呼び出す側でつかったら配列を引数に展開するやつ。

function f(a, ...b) {
  console.log(a); // => 1
  console.log(b); // => [2, 3]
}

f(...[1,2,3]);

for(;;)

無限ループ。
きちんとbreakすること。

function*

function* 宣言 (末尾にアスタリスクが付いたfunctionキーワード)は、 Generator オブジェクトを返すジェネレーター関数を定義します。

0
0
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
0
0