From da78a9e329e272dedb2400b79a3bdeebff387d47 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:42:17 -0500 Subject: initial commit --- .../operators/pipeline_operator/index.html | 76 ++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 files/ko/web/javascript/reference/operators/pipeline_operator/index.html (limited to 'files/ko/web/javascript/reference/operators/pipeline_operator') diff --git a/files/ko/web/javascript/reference/operators/pipeline_operator/index.html b/files/ko/web/javascript/reference/operators/pipeline_operator/index.html new file mode 100644 index 0000000000..42eb62e545 --- /dev/null +++ b/files/ko/web/javascript/reference/operators/pipeline_operator/index.html @@ -0,0 +1,76 @@ +--- +title: 파이프 연산자 +slug: Web/JavaScript/Reference/Operators/Pipeline_operator +tags: + - Experimental + - JavaScript + - Operator +translation_of: Web/JavaScript/Reference/Operators/Pipeline_operator +--- +
{{jsSidebar("Operators")}} {{SeeCompatTable}}
+ +

파이프 연산자(|>)는 실험적 기능(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
+
+ +

명세

+ + + + + + + + + + + + + + + + +
SpecificationStatusComment
Pipeline operator draftStage 1Not part of the ECMAScript specification yet.
+ +

브라우저 호환성

+ +
+ + +

{{Compat("javascript.operators.pipeline")}}

+
+ +

같이 보기

+ + -- cgit v1.2.3-54-g00ecf