Các tình nguyện viên của chúng tôi chưa dịch bài viết này thành Tiếng Việt. Tham gia với chúng tôi và hoàn thành công việc!
Bạn cũng có thể đọc bài viết trongEnglish (US).

This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

The experimental pipeline operator |> (currently at stage 1) pipes the value of an expression into a function. This allows the creation of chained function calls in a readable manner. The result is syntactic sugar in which a function call with a single argument can be written like this:

let url = "%21" |> decodeURI;

The equivalent call in traditional syntax looks like this:

let url = decodeURI("%21");


expression |> function

The value of the specified expression is passed into the function as its sole parameter.


Chaining function calls

The pipeline operator can improve readability when chaining several functions.

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


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

Browser compatibility

Update compatibility data on GitHub
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung InternetNode.js
Pipeline operator (|>)
Chrome No support NoEdge No support NoFirefox No support NoIE No support NoOpera No support NoSafari No support NoWebView Android No support NoChrome Android No support NoFirefox Android No support NoOpera Android No support NoSafari iOS No support NoSamsung Internet Android No support Nonodejs No support No


No support  
No support
Experimental. Expect behavior to change in the future.
Experimental. Expect behavior to change in the future.

See also

Document Tags and Contributors

Những người đóng góp cho trang này: Himself65, mdnwebdocs-bot, Sheppy, sideshowbarker, charnz, cbalisky, DingoEatingFuzz, qwertypants, fscholz
Cập nhật lần cuối bởi: Himself65,