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
©xgqfrms 2012-2020
www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/13415794.html
未经授权禁止转载,违者必究!