LoginSignup
13
7

More than 5 years have passed since last update.

ES2019に入りそうな機能

Last updated at Posted at 2018-12-12

出典:https://github.com/tc39/ecma262
※現時点で、ES2019に採用されるかは未確定です。

optional-catch-binding(Stage4)

try...catchcatchの引数が必須でなくなる。
実装状況(MDN)

try {
  //処理
} catch (e) {}

が、↓でもよくなる

try {
  //処理
} catch {}

json-superset(Stage4)

JSONにおいて、エスケープされていないU+2028(LINE SEPARATOR)とU+2029(PARAGRAPH SEPARATOR)が扱えるようになる。
実装状況(MDN)

以下のような問題が解決されるはず
JSONPで受け取れない文字? \u2028 - Qiita

Symbol.prototype.description(Stage4)

Symbolオブジェクトのdescriptionのみを返す。
実装状況(MDN)

Symbol('foo').description; // "foo"
Symbol('foo').toString();  // "Symbol(foo)"

Array.prototype.flat()(Stage3)

Arrayの次元を下げることができる。
実装状況(MDN)

[1, [2, 3, 4]].flat(); //[1, 2, 3, 4]
[1, [2, [3, 4]]].flat(2); //[1, 2, 3, 4]

Array.prototype.flatMap()(Stage3)

Array.prototype.map()の次元を1下げて返すバージョン。
実装状況(MDN)

[1, 2, 3, 4].flatMap(v => [v]); //[1, 2, 3, 4]
[1, 2, 3, 4].map(v => [v]); //[[1], [2], [3], [4]]

使い所が思いつかない🤔

globalThis(Stage3)

グローバルオブジェクトを取得する統一された方法が無かったため、生み出された。

globalThis === window; //true

こちらが詳しいです。
👻globalThis👻と🌏global🌏と🌝this🌝 - Qiita

dynamic-import(Stage3)

import()を使って動的にモジュールを読み込めるようになる。
実装状況(MDN)

const myModule = await import('my-module.js');

こちらが詳しいです。
Chrome、Safariで使えるJavaScriptのdynamic import(動的読み込み) - Qiita

BigInt(Stage3)

任意精度の整数を扱えるようになる。(現在number型で正確に扱える最大の整数は9007199254740991)

BigInt(9007199254740991);
9007199254740991n; //リテラル表記

こちらが詳しいです。
Chrome 67からJavaScriptのプリミティブ型BigIntが使用可能に - Qiita

Object.fromEntries()(Stage3)

キーと値を持つArrayかMapをオブジェクトに変換できる。(Object.entries()の逆)
実装状況(MDN)

Object.fromEntries([['a', 1], ['b', 2]]);
//{ a: 1, b: 2 }

String.prototype.{trimStart(),trimEnd()}(Stage3)

String.prototype.trim()の(左|右)側の空白のみ取り除くバージョン。
trimLeft(),trimRight()はエイリアス。
実装状況(MDN)

' a '.trimStart(); //"a "
' a '.trimLeft();  //"a "
' a '.trimEnd();   //" a"
' a '.trimRight(); //" a"
13
7
2

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