diff options
author | Florian Dieminger <me@fiji-flo.de> | 2021-02-11 18:29:51 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-11 18:29:51 +0100 |
commit | 2bc5610921312613f8623f7ed347aa576689b2b6 (patch) | |
tree | f17a7a00e232c97d1335ff3cb24dbcfafacfe141 /files/zh-cn/web/javascript/reference/operators/pipeline_operator | |
parent | 964decad361766e85d928a56f0ab80af0e75c172 (diff) | |
parent | fc56124ac4eda6b3f0349c8a16fa750f27b4c7d6 (diff) | |
download | translated-content-2bc5610921312613f8623f7ed347aa576689b2b6.tar.gz translated-content-2bc5610921312613f8623f7ed347aa576689b2b6.tar.bz2 translated-content-2bc5610921312613f8623f7ed347aa576689b2b6.zip |
Merge pull request #32 from fiji-flo/unslugging-zh-cn
Unslugging zh cn
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.html | 76 |
1 files changed, 76 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..d8087ba0e3 --- /dev/null +++ b/files/zh-cn/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 +original_slug: Web/JavaScript/Reference/Operators/管道操作符 +--- +<div>{{jsSidebar("Operators")}} {{SeeCompatTable}}</div> + +<p>试验性的管道操作符 <code>|></code> (目前其标准化流程处于 stage 1 阶段)允许以一种易读的方式去对函数链式调用。本质上来说,管道操作符是单参数函数调用的语法糖,它允许你像这样执行一个调用:</p> + +<pre class="brush: js">let url = "%21" |> decodeURI;</pre> + +<p>使用传统语法写的话,等效的代码是这样的:</p> + +<pre class="brush: js">let url = decodeURI("%21"); +</pre> + +<h2 id="语法">语法</h2> + +<pre class="syntaxbox">expression |> function</pre> + +<h2 id="例子">例子</h2> + +<h3 id="函数链式调用">函数链式调用</h3> + +<p>当链式调用多个函数时,使用管道操作符可以改善代码的可读性。</p> + +<pre class="brush: js">const double = (n) => n * 2; +const increment = (n) => n + 1; + +// 没有用管道操作符 +double(increment(double(5))); // 22 + +// 用上管道操作符之后 +5 |> double |> increment |> 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> |