aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/orphaned/web/javascript
diff options
context:
space:
mode:
authorMDN <actions@users.noreply.github.com>2021-05-29 01:14:43 +0000
committerMDN <actions@users.noreply.github.com>2021-05-29 01:14:43 +0000
commitd94b4f47476bbc901753f68d6dfe317e1c5c732e (patch)
tree590036437f5c828d71f35d6880228be2b4361b50 /files/zh-cn/orphaned/web/javascript
parent05a7219ba9605649cb6daa281e26209eaa73adf0 (diff)
downloadtranslated-content-d94b4f47476bbc901753f68d6dfe317e1c5c732e.tar.gz
translated-content-d94b4f47476bbc901753f68d6dfe317e1c5c732e.tar.bz2
translated-content-d94b4f47476bbc901753f68d6dfe317e1c5c732e.zip
[CRON] sync translated content
Diffstat (limited to 'files/zh-cn/orphaned/web/javascript')
-rw-r--r--files/zh-cn/orphaned/web/javascript/reference/operators/pipeline_operator/index.html76
1 files changed, 76 insertions, 0 deletions
diff --git a/files/zh-cn/orphaned/web/javascript/reference/operators/pipeline_operator/index.html b/files/zh-cn/orphaned/web/javascript/reference/operators/pipeline_operator/index.html
new file mode 100644
index 0000000000..12c3b6fbb3
--- /dev/null
+++ b/files/zh-cn/orphaned/web/javascript/reference/operators/pipeline_operator/index.html
@@ -0,0 +1,76 @@
+---
+title: 管道操作符
+slug: orphaned/Web/JavaScript/Reference/Operators/Pipeline_operator
+tags:
+ - Experimental
+ - JavaScript
+ - Operator
+ - 语法糖
+ - 链式
+ - 链式调用
+translation_of: Web/JavaScript/Reference/Operators/Pipeline_operator
+original_slug: 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>