実験段階のパイプライン演算子 |> (現在はステージ 1 です) は、読みやすい方法で一連の関数呼び出しをできます。基本的に、パイプライン演算子は 1 つの引数を受け取る関数呼び出しのシンタックスシュガーを提供します。たとえば、次のように、
decodeURI('%21') の代わりに '%21' |> decodeURI と記述できます。
構文
expression |> function
例
関数呼び出しチェーン
パイプライン演算子は、複数関数の呼び出しを読みやすくしてくれます。
const double = (n) => n * 2; const increment = (n) => n + 1; // パイプライン演算子なし double(increment(double(10))); // 42 // パイプライン演算子あり 10 |> double |> increment |> double; // 42
仕様
| 仕様 | ステータス | コメント |
|---|---|---|
| パイプライン演算子草案 | ステージ 1 | まだ ECMAScript 仕様ではありません。 |
ブラウザー実装状況
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.