ES2021 & Pipeline operator (|>) / 管道運算符 |>


ES2021 & Pipeline operator (|>) / 管道運算符 |>

demo


"use strict";

/**
 *
 * @author xgqfrms
 * @license MIT
 * @copyright xgqfrms
 * @created 2020-08-01
 * @modified
 *
 * @description Pipeline operator (|>) / 管道運算符 |>
 * @difficulty Easy Medium Hard
 * @complexity O(n)
 * @augments
 * @example
 * @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Pipeline_operator
 * @solutions
 *
 */

const log = console.log;

/*

expression |> function

// 實驗性管道運算符|>(當前處於階段1)將表達式的值通過管道傳遞給函數。

*/

const double = (n) => n * 2;
const increment = (n) => n + 1;

// without pipeline operator
double(increment(double(double(5))));
// 42

// with pipeline operator
5 |> double |> double |> increment |> double;
// 42


refs

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Pipeline_operator


Flag Counter

©xgqfrms 2012-2020

www.cnblogs.com 發布文章使用:只允許注冊用戶才可以訪問!



免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM