This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
파이프 연산자(|>
)는 실험적 기능(stage 1)으로, 표현식의 값을 함수에 전달합니다. 파이프 연산자를 활용하면 중첩 함수 호출을 좀 더 읽기 좋은 형식으로 작성할 수 있습니다. 결과물은 문법적 설탕syntactic sugar으로, 하나의 인수를 제공하는 함수 호출은 다음 코드처럼 쓸 수 있습니다.
let url = "%21" |> decodeURI;
전통적인 구문에서는 아래처럼 호출합니다.
let url = decodeURI("%21");
구문
expression |> function
지정한 expression
의 값이 function
의 유일한 매개변수로 전달됩니다.
예제
함수 체이닝
파이프 연산자를 사용해, 여러 번 중첩된 함수 호출을 읽기 편한 형태로 바꿀 수 있습니다.
const double = (n) => n * 2;
const increment = (n) => n + 1;
// 파이프 연산자 없이
double(increment(double(double(5)))); // 42
// 파이프 연산자 사용
5 |> double |> double |> increment |> double; // 42
명세
Specification | Status | Comment |
---|---|---|
Pipeline operator draft | Stage 1 | Not part of the ECMAScript specification yet. |
브라우저 호환성
BCD tables only load in the browser
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.