这是一个实验中的功能
此功能某些浏览器尚在开发中,请参考浏览器兼容性表格以得到在不同浏览器中适合使用的前缀。由于该功能对应的标准文档可能被重新修订,所以在未来版本的浏览器中该功能的语法和行为可能随之改变。
试验性的管道操作符 |>
(目前在 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
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.
Update compatibility data on GitHub
Desktop | Mobile | Server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Basic support | Chrome No support No | Edge No support No | Firefox
Full support
58
| IE No support No | Opera No support No | Safari No support No | WebView Android No support No | Chrome Android No support No | Edge Mobile No support No | Firefox Android
Full support
58
| Opera Android No support No | Safari iOS No support No | Samsung Internet Android No support No | nodejs 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.