这是一个实验中的功能
此功能某些浏览器尚在开发中,请参考浏览器兼容性表格以得到在不同浏览器中适合使用的前缀。由于该功能对应的标准文档可能被重新修订,所以在未来版本的浏览器中该功能的语法和行为可能随之改变。

试验性的管道操作符 |> (目前在 stage 1阶段)允许以一种易读的方式去对函数链式调用。本质上来说,管道操作符是单参数函数调用的语法糖,它允许你以'%21' |> decodeURI来替代decodeURI('%21')

语法

expression |> function

例子

函数链式调用

当几个函数链式调用时,使用管道操作符可以增强代码的可读性。

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

// 没有用管道操作符
double(increment(double(5))); // 22

// 用上管道操作符之后
5 |> double |> increment |> double; // 22

规范

Specification Status Comment
Pipeline operator draft Stage 1 Not part of the ECMAScript specification yet.

浏览器兼容性Edit

Update compatibility data on GitHub
DesktopMobileServer
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidSafari on iOSSamsung InternetNode.js
Basic support
Experimental
Chrome No support NoEdge No support NoFirefox Full support 58
Disabled
Full support 58
Disabled
Disabled From version 58: this feature is behind the --enable-pipeline-operator compile flag.
IE No support NoOpera No support NoSafari No support NoWebView Android No support NoChrome Android No support NoEdge Mobile No support NoFirefox Android Full support 58
Disabled
Full support 58
Disabled
Disabled From version 58: this feature is behind the --enable-pipeline-operator compile flag.
Opera Android No support NoSafari iOS No support NoSamsung Internet Android No support Nonodejs No support No

Legend

Full support  
Full support
No support  
No support
Experimental. Expect behavior to change in the future.
Experimental. Expect behavior to change in the future.
User must explicitly enable this feature.
User must explicitly enable this feature.

相关链接

文档标签和贡献者

标签: 
此页面的贡献者: fsy0718, zhangchen, qdlaoyao, fphonor
最后编辑者: fsy0718,