aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/javascript/reference
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-11 18:59:39 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-11 18:59:39 -0500
commitd192fb918b0e2aa8869de6dcc59de8464b6e879a (patch)
tree3dc6f395a53be89041c52e9326baf908ffa3f3a6 /files/zh-cn/web/javascript/reference
parente3e12548adeb7e1dcfc4d5b32884a225ee2b499d (diff)
downloadtranslated-content-d192fb918b0e2aa8869de6dcc59de8464b6e879a.tar.gz
translated-content-d192fb918b0e2aa8869de6dcc59de8464b6e879a.tar.bz2
translated-content-d192fb918b0e2aa8869de6dcc59de8464b6e879a.zip
dump 2020-12-11
Diffstat (limited to 'files/zh-cn/web/javascript/reference')
-rw-r--r--files/zh-cn/web/javascript/reference/global_objects/math/random/index.html2
-rw-r--r--files/zh-cn/web/javascript/reference/global_objects/promise/all/index.html18
-rw-r--r--files/zh-cn/web/javascript/reference/global_objects/regexp/index.html12
-rw-r--r--files/zh-cn/web/javascript/reference/global_objects/unescape/index.html6
-rw-r--r--files/zh-cn/web/javascript/reference/operators/instanceof/index.html14
5 files changed, 25 insertions, 27 deletions
diff --git a/files/zh-cn/web/javascript/reference/global_objects/math/random/index.html b/files/zh-cn/web/javascript/reference/global_objects/math/random/index.html
index 46aad728b8..ea760c65f6 100644
--- a/files/zh-cn/web/javascript/reference/global_objects/math/random/index.html
+++ b/files/zh-cn/web/javascript/reference/global_objects/math/random/index.html
@@ -11,7 +11,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Math/random
---
<div>{{JSRef}}</div>
-<div><code><strong>Math.random()</strong></code> 函数返回一个浮点,  伪随机数在范围从<strong>0到</strong>小于<strong>1</strong>,也就是说,从0(包括0)往上,但是不包括1(排除1),然后您可以缩放到所需的范围。实现将初始种子选择到随机数生成算法;它不能被用户选择或重置。</div>
+<div><code><strong>Math.random()</strong></code> 函数返回一个浮点数,  伪随机数在范围从<strong>0到</strong>小于<strong>1</strong>,也就是说,从0(包括0)往上,但是不包括1(排除1),然后您可以缩放到所需的范围。实现将初始种子选择到随机数生成算法;它不能被用户选择或重置。</div>
<p>{{EmbedInteractiveExample("pages/js/math-random.html")}}</p>
diff --git a/files/zh-cn/web/javascript/reference/global_objects/promise/all/index.html b/files/zh-cn/web/javascript/reference/global_objects/promise/all/index.html
index 84264ce68b..e81f816fbf 100644
--- a/files/zh-cn/web/javascript/reference/global_objects/promise/all/index.html
+++ b/files/zh-cn/web/javascript/reference/global_objects/promise/all/index.html
@@ -13,9 +13,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Promise/all
---
<div>{{JSRef}}</div>
-<p><code><strong>Promise.all(iterable)</strong></code> 方法返回一个 {{jsxref("Promise")}} 实例,此实例在 <code>iterable</code> 参数内所有的 <code>promise</code> 都“完成(resolved)”或参数中不包含 <code>promise</code> 时回调完成(resolve);如果参数中  <code>promise</code> 有一个失败(rejected),此实例回调失败(reject),失败的原因是第一个失败 <code>promise</code> 的结果。</p>
-
-<p>它通常在启动多个异步任务并发运行并为其结果创建承诺之后使用,以便人们可以等待所有任务完成。</p>
+<p>Promise.all() 方法接收一个promise的idterable类型(注:Array,Map,Set都属于ES6的iterable类型)的输入,并且只返回一个{{jsxref("Promise")}}实例, 那个输入的所有promise的resolve回调的结果是一个数组。这个{{jsxref("Promise")}}的resolve回调执行是在所有输入的promise的resolve回调都结束,或者输入的iterable里没有promise了的时候。它的reject回调执行是,只要任何一个输入的promise的reject回调执行或者输入不合法的promise就会立即抛出错误,并且reject的是第一个抛出的错误信息。</p>
<div>{{EmbedInteractiveExample("pages/js/promise-all.html")}}</div>
@@ -23,7 +21,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Promise/all
<h2 id="语法">语法</h2>
-<pre class="syntaxbox"><var>Promise.all(iterable)</var>;</pre>
+<pre class="syntaxbox notranslate"><var>Promise.all(iterable)</var>;</pre>
<h3 id="参数">参数</h3>
@@ -58,7 +56,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Promise/all
<p><code>Promise.all</code> 等待所有都完成(或第一个失败)。</p>
-<pre class="brush: js">var p1 = Promise.resolve(3);
+<pre class="brush: js notranslate">var p1 = Promise.resolve(3);
var p2 = 1337;
var p3 = new Promise((resolve, reject) =&gt; {
setTimeout(resolve, 100, 'foo');
@@ -70,7 +68,7 @@ Promise.all([p1, p2, p3]).then(values =&gt; {
<p>如果参数中包含非 <code>promise</code> 值,这些值将被忽略,但仍然会被放在返回数组中(如果 <code>promise</code> 完成的话):</p>
-<pre class="brush: js">// this will be counted as if the iterable passed is empty, so it gets fulfilled
+<pre class="brush: js notranslate">// this will be counted as if the iterable passed is empty, so it gets fulfilled
var p = Promise.all([1,2,3]);
// this will be counted as if the iterable passed contains only the resolved promise with value "444", so it gets fulfilled
var p2 = Promise.all([1,2,3, Promise.resolve(444)]);
@@ -93,7 +91,7 @@ setTimeout(function(){
<p>下面的例子中演示了 <code>Promise.all</code> 的异步性(如果传入的可迭代对象是空的,就是同步):</p>
-<pre class="brush: js">// we are passing as argument an array of promises that are already resolved,
+<pre class="brush: js notranslate">// we are passing as argument an array of promises that are already resolved,
// to trigger Promise.all as soon as possible
var resolvedPromisesArray = [Promise.resolve(33), Promise.resolve(44)];
@@ -115,7 +113,7 @@ setTimeout(function(){
<p>如果 <code>Promise.all</code> 失败,也是一样的:</p>
-<pre class="brush: js">var mixedPromisesArray = [Promise.resolve(33), Promise.reject(44)];
+<pre class="brush: js notranslate">var mixedPromisesArray = [Promise.resolve(33), Promise.reject(44)];
var p = Promise.all(mixedPromisesArray);
console.log(p);
setTimeout(function(){
@@ -131,7 +129,7 @@ setTimeout(function(){
<p>但是,<code>Promise.all</code> <strong>当且仅当</strong>传入的可迭代对象为空时为同步:</p>
-<pre class="brush: js">var p = Promise.all([]); // will be immediately resolved
+<pre class="brush: js notranslate">var p = Promise.all([]); // will be immediately resolved
var p2 = Promise.all([1337, "hi"]); // non-promise values will be ignored, but the evaluation will be done asynchronously
console.log(p);
console.log(p2)
@@ -151,7 +149,7 @@ setTimeout(function(){
<p><code>Promise.all</code> 在任意一个传入的 <code>promise</code> 失败时返回失败。例如,如果你传入的 <code>promise</code>中,有四个 <code>promise</code> 在一定的时间之后调用成功函数,有一个立即调用失败函数,那么 <code>Promise.all</code> 将立即变为失败。</p>
-<pre class="brush: js">var p1 = new Promise((resolve, reject) =&gt; {
+<pre class="brush: js notranslate">var p1 = new Promise((resolve, reject) =&gt; {
setTimeout(resolve, 1000, 'one');
});
var p2 = new Promise((resolve, reject) =&gt; {
diff --git a/files/zh-cn/web/javascript/reference/global_objects/regexp/index.html b/files/zh-cn/web/javascript/reference/global_objects/regexp/index.html
index 77e10c7396..27da890c46 100644
--- a/files/zh-cn/web/javascript/reference/global_objects/regexp/index.html
+++ b/files/zh-cn/web/javascript/reference/global_objects/regexp/index.html
@@ -1,5 +1,5 @@
---
-title: RegExp
+title: RegExp(正则表达式)
slug: Web/JavaScript/Reference/Global_Objects/RegExp
tags:
- Class
@@ -23,16 +23,16 @@ translation_of: Web/JavaScript/Reference/Global_Objects/RegExp
<dl>
<dt>字面量</dt>
- <dd>由斜杠包围而不是引号包围。</dd>
+ <dd>由斜杠(/)包围而不是引号包围。</dd>
<dt>构造函数的字符串参数</dt>
<dd>由引号而不是斜杠包围。</dd>
</dl>
<p>以下三种表达式都会创建相同的正则表达式:</p>
-<pre class="brush: js notranslate" style="font-size: 14px;">/ab+c/i;
-new RegExp('ab+c', 'i');
-new RegExp(/ab+c/, 'i');</pre>
+<pre class="brush: js notranslate" style="font-size: 14px;">/ab+c/i; //字面量形式
+new RegExp('ab+c', 'i'); // 首个参数为字符串模式的构造函数
+new RegExp(/ab+c/, 'i'); // 首个参数为常规字面量的构造函数</pre>
<p>当表达式被赋值时,字面量形式提供正则表达式的编译(compilation)状态,当正则表达式保持为常量时使用字面量。例如当你在循环中使用字面量构造一个正则表达式时,正则表达式不会在每一次迭代中都被重新编译(recompiled)。</p>
@@ -258,7 +258,7 @@ console.log(/[^.]+/.exec(url)[0].substr(7)); // logs "xxx"
console.log("'group:" + group + "'");
}); // 'group:undefined'</code></pre>
-<p>注意,由于web兼容性 <code>RegExp.$N</code> 仍会返回一个空的字符串代替 <code>undefined</code> ({{bug(1053944)}}).</p>
+<p>注意,由于web兼容性 <code>RegExp.$N</code> 仍会返回一个空的字符串代替 <code>undefined</code> (<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1053944">bug 1053944</a>).</p>
<h2 id="相关链接">相关链接</h2>
diff --git a/files/zh-cn/web/javascript/reference/global_objects/unescape/index.html b/files/zh-cn/web/javascript/reference/global_objects/unescape/index.html
index b85895a7cd..59df2809d8 100644
--- a/files/zh-cn/web/javascript/reference/global_objects/unescape/index.html
+++ b/files/zh-cn/web/javascript/reference/global_objects/unescape/index.html
@@ -9,11 +9,11 @@ translation_of: Web/JavaScript/Reference/Global_Objects/unescape
<p><font face="Open Sans, Arial, sans-serif">已废弃的</font><code><strong>unescape()</strong></code> 方法计算生成一个新的字符串,其中的十六进制转义序列将被其表示的字符替换。上述的转义序列就像{{jsxref("escape")}}里介绍的一样。因为 <code>unescape</code> 已经废弃,建议使用 {{jsxref("decodeURI")}}或者{{jsxref("decodeURIComponent")}} 替代本方法。</p>
-<div class="note"><strong>注意:</strong>不要使用<code>unescape</code>去解码URLS,使用<code>decodeURI</code>替代。</div>
+<div class="note"><strong>注意:</strong>不要使用<code>unescape</code>去解码URLS,使用<code>decodeURI</code>或<code>decodeURIComponent</code>替代。</div>
<h2 id="语法">语法</h2>
-<pre class="syntaxbox"><code>unescape(str)</code></pre>
+<pre class="syntaxbox notranslate"><code>unescape(str)</code></pre>
<h3 id="参数">参数</h3>
@@ -32,7 +32,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/unescape
<h2 id="示例">示例</h2>
-<pre class="brush: js">unescape('abc123'); // "abc123"
+<pre class="brush: js notranslate">unescape('abc123'); // "abc123"
unescape('%E4%F6%FC'); // "äöü"
unescape('%u0107'); // "ć"
</pre>
diff --git a/files/zh-cn/web/javascript/reference/operators/instanceof/index.html b/files/zh-cn/web/javascript/reference/operators/instanceof/index.html
index c97b2a72a4..d637cf41e1 100644
--- a/files/zh-cn/web/javascript/reference/operators/instanceof/index.html
+++ b/files/zh-cn/web/javascript/reference/operators/instanceof/index.html
@@ -20,7 +20,7 @@ translation_of: Web/JavaScript/Reference/Operators/instanceof
<h2 id="Syntax" name="Syntax">语法</h2>
-<pre><code><em>object</em> instanceof <em>constructor</em></code></pre>
+<pre class="notranslate"><code><em>object</em> instanceof <em>constructor</em></code></pre>
<h3 id="Parameters" name="Parameters">参数</h3>
@@ -38,7 +38,7 @@ translation_of: Web/JavaScript/Reference/Operators/instanceof
<p><code>instanceof</code> 运算符用来检测 <code>constructor.prototype </code>是否存在于参数 <code>object</code> 的原型链上。</p>
-<pre class="brush: js">// 定义构造函数
+<pre class="brush: js notranslate">// 定义构造函数
function C(){}
function D(){}
@@ -87,14 +87,14 @@ o3 instanceof C; // true 因为 C.prototype 现在在 o3 的原型链上
<p>但是,使用对象文字符号创建的对象在这里是一个例外:虽然原型未定义,但 <code>instanceof Object</code> 返回 <code>true</code>。</p>
-<pre class="brush: js">var simpleStr = "This is a simple string";
+<pre class="brush: js notranslate">var simpleStr = "This is a simple string";
var myString = new String();
var newStr = new String("String created with constructor");
var myDate = new Date();
var myObj = {};
var myNonObj = Object.create(null);
-simpleStr instanceof String; // 返回 false, 检查原型链会找到 undefined
+simpleStr instanceof String; // 返回 false, 非对象实例,因此返回 false
myString instanceof String; // 返回 true
newStr instanceof String; // 返回 true
myString instanceof Object; // 返回 true
@@ -113,7 +113,7 @@ myDate instanceof String; // 返回 false</pre>
<p>下面的代码创建了一个类型 <code>Car</code>,以及该类型的对象实例 <code>mycar</code>. <code>instanceof</code> 运算符表明了这个 <code>mycar</code> 对象既属于 <code>Car</code> 类型,又属于 <code>Object</code> 类型。</p>
-<pre class="brush: js" dir="rtl">function Car(make, model, year) {
+<pre class="brush: js notranslate" dir="rtl">function Car(make, model, year) {
this.make = make;
this.model = model;
this.year = year;
@@ -128,13 +128,13 @@ var b = mycar instanceof Object; // 返回 true
<p>要检测对象不是某个构造函数的实例时,你可以这样做</p>
-<pre class="brush: js">if (!(mycar instanceof Car)) {
+<pre class="brush: js notranslate">if (!(mycar instanceof Car)) {
// Do something, like mycar = new Car(mycar)
}</pre>
<p>这和以下代码完全不同</p>
-<pre class="brush: js">if (!mycar instanceof Car)</pre>
+<pre class="brush: js notranslate">if (!mycar instanceof Car)</pre>
<p>这段代码永远会得到 <code>false</code>(<code>!mycar</code> 将在 <code>instanceof</code> 之前被处理,所以你总是在验证一个布尔值是否是 <code>Car</code> 的一个实例)。</p>