aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web
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
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')
-rw-r--r--files/zh-cn/web/api/parentnode/queryselectorall/index.html24
-rw-r--r--files/zh-cn/web/css/url/index.html3
-rw-r--r--files/zh-cn/web/html/element/tr/index.html16
-rw-r--r--files/zh-cn/web/javascript/a_re-introduction_to_javascript/index.html4
-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
9 files changed, 49 insertions, 50 deletions
diff --git a/files/zh-cn/web/api/parentnode/queryselectorall/index.html b/files/zh-cn/web/api/parentnode/queryselectorall/index.html
index 1664ec5559..2f7bc72f71 100644
--- a/files/zh-cn/web/api/parentnode/queryselectorall/index.html
+++ b/files/zh-cn/web/api/parentnode/queryselectorall/index.html
@@ -16,7 +16,7 @@ translation_of: Web/API/ParentNode/querySelectorAll
<p>The {{domxref("ParentNode")}} mixin defines the <code><strong>querySelectorAll()</strong></code> method 返回一个 {{domxref("NodeList")}} 表示元素的列表,把当前的元素作为根与指定的选择器组相匹配。</p>
-<p>If you need only a single result, consider the {{domxref("ParentNode.querySelector", "querySelector()")}} method instead.</p>
+<p>如果你只需要一个结果,可以考虑使用{{domxref("ParentNode.querySelector", "querySelector()")}}方法来代替。</p>
<div class="note">
<p><strong>Note:</strong> This method is implemented as {{domxref("Element.querySelectorAll()")}}, {{domxref("Document.querySelectorAll()")}}, and {{domxref("DocumentFragment.querySelectorAll()")}}</p>
@@ -24,7 +24,7 @@ translation_of: Web/API/ParentNode/querySelectorAll
<h2 id="语法">语法</h2>
-<pre class="syntaxbox"><var>elementList</var> = <em>parentNode</em>.querySelectorAll(<var>selectors</var>);
+<pre class="syntaxbox notranslate"><var>elementList</var> = <em>parentNode</em>.querySelectorAll(<var>selectors</var>);
</pre>
<h3 id="参数">参数</h3>
@@ -41,10 +41,10 @@ translation_of: Web/API/ParentNode/querySelectorAll
<h3 id="返回值">返回值</h3>
-<p>A non-live {{domxref("NodeList")}} containing one {{domxref("Element")}} object for each descendant node that matches at least one of the specified selectors.</p>
+<p>一个不存活的 {{domxref("NodeList")}} ,每个子节点拥有一个 {{domxref("Element")}} 对象,其中每个子节点至少与一个选择器相匹配。</p>
<div class="note">
-<p><strong>Note:</strong> If the specified <code>selectors</code> include a <a href="/en-US/docs/Web/CSS/Pseudo-elements">CSS pseudo-element</a>, the returned list is always empty.</p>
+<p><strong>Note:</strong> 如果指定的 <code>selectors</code> 包含<a href="/en-US/docs/Web/CSS/Pseudo-elements">CSS pseudo-element</a>,那么返回的列表始终为空。</p>
</div>
<h3 id="Exceptions">Exceptions</h3>
@@ -58,24 +58,24 @@ translation_of: Web/API/ParentNode/querySelectorAll
<p>To obtain a {{domxref("NodeList")}} of all of the {{HTMLElement("p")}} elements in the document:</p>
-<pre class="brush: js">var matches = document.querySelectorAll("p");</pre>
+<pre class="brush: js notranslate">var matches = document.querySelectorAll("p");</pre>
<p>这个例子返回了所有 class 为 "note" 或者 "alert" 的 div 元素的一个列表:</p>
-<pre class="brush: js">var matches = document.querySelectorAll("div.note, div.alert");</pre>
+<pre class="brush: js notranslate">var matches = document.querySelectorAll("div.note, div.alert");</pre>
<p>Here, we get a list of <code>&lt;p&gt;</code> elements whose immediate parent element is a {{domxref("div")}} with the class <code>"highlighted"</code> and which are located inside a container whose ID is <code>"test"</code>.</p>
-<pre class="brush: js">var container = document.querySelector("#test");
+<pre class="brush: js notranslate">var container = document.querySelector("#test");
var matches = container.querySelectorAll("div.highlighted &gt; p");</pre>
<p>This example uses an <a href="/en-US/docs/Web/CSS/Attribute_selectors">attribute selector</a> to return a list of the {{domxref("iframe")}} elements in the document that contain an attribute named <code>"data-src"</code>:</p>
-<pre class="brush: js">var matches = document.querySelectorAll("iframe[data-src]");</pre>
+<pre class="brush: js notranslate">var matches = document.querySelectorAll("iframe[data-src]");</pre>
<p>Here, an attribute selector is used to return a list of the list items contained within a list whose ID is <code>"userlist"</code> which have a <code>"data-active"</code> attribute whose value is <code>"1"</code>:</p>
-<pre class="brush: js">var container = document.querySelector("#userlist");
+<pre class="brush: js notranslate">var container = document.querySelector("#userlist");
var matches = container.querySelectorAll("li[data-active=1]");</pre>
<h2 id="User_notes">User notes</h2>
@@ -86,7 +86,7 @@ var matches = container.querySelectorAll("li[data-active=1]");</pre>
<p>Consider this HTML, with its three nested {{HTMLElement("div")}} blocks.</p>
-<pre class="brush: html">&lt;div class="outer"&gt;
+<pre class="brush: html notranslate">&lt;div class="outer"&gt;
&lt;div class="select"&gt;
&lt;div class="inner"&gt;
&lt;/div&gt;
@@ -95,7 +95,7 @@ var matches = container.querySelectorAll("li[data-active=1]");</pre>
<h3 id="JavaScript">JavaScript</h3>
-<pre class="brush: js">var select = document.querySelector('.select');
+<pre class="brush: js notranslate">var select = document.querySelector('.select');
var inner = select.querySelectorAll('.outer .inner');
inner.length; // 1, not 0!
</pre>
@@ -104,7 +104,7 @@ inner.length; // 1, not 0!
<p>The {{cssxref(":scope")}} pseudo-class restores the expected behavior, only matching selectors on descendants of the base element:</p>
-<pre class="brush: js">var select = document.querySelector('.select');
+<pre class="brush: js notranslate">var select = document.querySelector('.select');
var inner = select.querySelectorAll(':scope .outer .inner');
inner.length; // 0</pre>
diff --git a/files/zh-cn/web/css/url/index.html b/files/zh-cn/web/css/url/index.html
index 9b3451e3d7..3ba85545e4 100644
--- a/files/zh-cn/web/css/url/index.html
+++ b/files/zh-cn/web/css/url/index.html
@@ -1,7 +1,8 @@
---
title: <url>
slug: Web/CSS/url
-translation_of: Web/CSS/url
+translation_of: Web/CSS/url()
+translation_of_original: Web/CSS/url
---
<p>{{ CssRef() }}</p>
diff --git a/files/zh-cn/web/html/element/tr/index.html b/files/zh-cn/web/html/element/tr/index.html
index a7b41a75d4..a5ccfcacd7 100644
--- a/files/zh-cn/web/html/element/tr/index.html
+++ b/files/zh-cn/web/html/element/tr/index.html
@@ -3,7 +3,7 @@ title: <tr>
slug: Web/HTML/Element/tr
translation_of: Web/HTML/Element/tr
---
-<p><strong>HTML <code>&lt;tr&gt;</code> 元素</strong>定义表格中的行。 Those can be a mix of {{HTMLElement("td")}} and {{HTMLElement("th")}} elements.</p>
+<p><strong>HTML <code>&lt;tr&gt;</code> 元素</strong>定义表格中的行。 同一行可同时出现{{HTMLElement("td")}} 和{{HTMLElement("th")}} 元素.</p>
<table class="properties">
<tbody>
@@ -40,12 +40,12 @@ translation_of: Web/HTML/Element/tr
<dl>
<dt>{{htmlattrdef("align")}} {{deprecatedGeneric("inline","html4.01")}}, {{obsoleteGeneric("inline","html5")}}</dt>
- <dd>This enumerated attribute specifies how horizontal alignment of each cell content will be handled. Possible values are:
+ <dd>该枚举属性指定每个单元格中内容的水平对齐方式,可使用的属性值如下:
<ul>
- <li><code>left</code>, aligning the content to the left of the cells</li>
- <li><code>center</code>, centering the content in the cells</li>
- <li><code>right</code>, aligning the content to the right of the cells</li>
- <li><code>justify</code>, widening the spaces in the textual content so that the content is justified in the cells</li>
+ <li><code>left</code>, 内容在单元格中左对齐</li>
+ <li><code>center</code>, 内容在单元格中居中</li>
+ <li><code>right</code>, 内容在单元格中右对齐</li>
+ <li><code>justify</code>, 增加文本内容之间的空白以伸展这行文本,使得该单元格中的多行文本具有相同的长度。</li>
<li><code>char</code>, aligning the textual content on a special character with a minimal offset, defined by the {{htmlattrxref("char", "tr")}} and {{htmlattrxref("charoff", "tr")}} attributes {{unimplemented_inline("2212")}}</li>
</ul>
@@ -112,12 +112,12 @@ translation_of: Web/HTML/Element/tr
<tr>
<td>{{SpecName('HTML WHATWG','tables.html#the-tr-element','tr element')}}</td>
<td>{{Spec2('HTML WHATWG')}}</td>
- <td> </td>
+ <td></td>
</tr>
<tr>
<td>{{SpecName('HTML5 W3C','tabular-data.html#the-tr-element','tr element')}}</td>
<td>{{Spec2('HTML5 W3C')}}</td>
- <td> </td>
+ <td></td>
</tr>
</tbody>
</table>
diff --git a/files/zh-cn/web/javascript/a_re-introduction_to_javascript/index.html b/files/zh-cn/web/javascript/a_re-introduction_to_javascript/index.html
index 0f423505da..bcf94763b0 100644
--- a/files/zh-cn/web/javascript/a_re-introduction_to_javascript/index.html
+++ b/files/zh-cn/web/javascript/a_re-introduction_to_javascript/index.html
@@ -946,8 +946,8 @@ add20(7); // ?
<p>这里发生的事情和前面介绍过的内嵌函数十分相似:一个函数被定义在了另外一个函数的内部,内部函数可以访问外部函数的变量。唯一的不同是,外部函数已经返回了,那么常识告诉我们局部变量“应该”不再存在。但是它们却仍然存在——否则 <code>adder</code> 函数将不能工作。也就是说,这里存在 <code>makeAdder</code> 的局部变量的两个不同的“副本”——一个是 <code>a</code> 等于 5,另一个是 <code>a</code> 等于 20。那些函数的运行结果就如下所示:</p>
-<pre class="brush: js notranslate">x(6); // 返回 11
-y(7); // 返回 27
+<pre class="brush: js notranslate">add5(6); // 返回 11
+add20(7); // 返回 27
</pre>
<p>下面来说说,到底发生了什么了不得的事情。每当 JavaScript 执行一个函数时,都会创建一个作用域对象(scope object),用来保存在这个函数中创建的局部变量。它使用一切被传入函数的变量进行初始化(初始化后,它包含一切被传入函数的变量)。这与那些保存的所有全局变量和函数的全局对象(global object)相类似,但仍有一些很重要的区别:第一,每次函数被执行的时候,就会创建一个新的,特定的作用域对象;第二,与全局对象(如浏览器的 <code>window</code> 对象)不同的是,你不能从 JavaScript 代码中直接访问作用域对象,也没有 可以遍历当前作用域对象中的属性 的方法。</p>
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>