aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/javascript/reference/operators/pipeline_operator
diff options
context:
space:
mode:
authorFlorian Merz <me@fiji-flo.de>2021-02-11 12:56:40 +0100
committerFlorian Merz <me@fiji-flo.de>2021-02-11 12:56:40 +0100
commit310fd066e91f454b990372ffa30e803cc8120975 (patch)
treed5d900deb656a5da18e0b60d00f0db73f3a2e88e /files/zh-cn/web/javascript/reference/operators/pipeline_operator
parent8260a606c143e6b55a467edf017a56bdcd6cba7e (diff)
downloadtranslated-content-310fd066e91f454b990372ffa30e803cc8120975.tar.gz
translated-content-310fd066e91f454b990372ffa30e803cc8120975.tar.bz2
translated-content-310fd066e91f454b990372ffa30e803cc8120975.zip
unslug zh-cn: move
Diffstat (limited to 'files/zh-cn/web/javascript/reference/operators/pipeline_operator')
-rw-r--r--files/zh-cn/web/javascript/reference/operators/pipeline_operator/index.html75
1 files changed, 75 insertions, 0 deletions
diff --git a/files/zh-cn/web/javascript/reference/operators/pipeline_operator/index.html b/files/zh-cn/web/javascript/reference/operators/pipeline_operator/index.html
new file mode 100644
index 0000000000..06ce40ad0b
--- /dev/null
+++ b/files/zh-cn/web/javascript/reference/operators/pipeline_operator/index.html
@@ -0,0 +1,75 @@
+---
+title: 管道操作符
+slug: Web/JavaScript/Reference/Operators/管道操作符
+tags:
+ - Experimental
+ - JavaScript
+ - Operator
+ - 语法糖
+ - 链式
+ - 链式调用
+translation_of: Web/JavaScript/Reference/Operators/Pipeline_operator
+---
+<div>{{jsSidebar("Operators")}} {{SeeCompatTable}}</div>
+
+<p>试验性的管道操作符 <code>|&gt;</code> (目前其标准化流程处于 stage 1 阶段)允许以一种易读的方式去对函数链式调用。本质上来说,管道操作符是单参数函数调用的语法糖,它允许你像这样执行一个调用:</p>
+
+<pre class="brush: js">let url = "%21" |&gt; decodeURI;</pre>
+
+<p>使用传统语法写的话,等效的代码是这样的:</p>
+
+<pre class="brush: js">let url = decodeURI("%21");
+</pre>
+
+<h2 id="语法">语法</h2>
+
+<pre class="syntaxbox">expression |&gt; function</pre>
+
+<h2 id="例子">例子</h2>
+
+<h3 id="函数链式调用">函数链式调用</h3>
+
+<p>当链式调用多个函数时,使用管道操作符可以改善代码的可读性。</p>
+
+<pre class="brush: js">const double = (n) =&gt; n * 2;
+const increment = (n) =&gt; n + 1;
+
+// 没有用管道操作符
+double(increment(double(5))); // 22
+
+// 用上管道操作符之后
+5 |&gt; double |&gt; increment |&gt; double; // 22
+</pre>
+
+<h2 id="规范">规范</h2>
+
+<table class="standard-table">
+ <thead>
+ <tr>
+ <th scope="col">规范</th>
+ <th scope="col">状态</th>
+ <th scope="col">备注</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td><a href="http://tc39.github.io/proposal-pipeline-operator/">Pipeline operator draft</a></td>
+ <td>Stage 1</td>
+ <td>Not part of the ECMAScript specification yet.</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="浏览器兼容性Edit">浏览器兼容性<a class="button section-edit only-icon" href="https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators$edit#浏览器兼容性" rel="nofollow, noindex"><span>Edit</span></a></h2>
+
+<div>
+
+
+<p>{{Compat("javascript.operators.pipeline")}}</p>
+</div>
+
+<h2 id="参见">参见</h2>
+
+<ul>
+ <li>GitHub 上的 <a href="https://github.com/tc39/proposals">TC39/proposals</a></li>
+</ul>