aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/javascript/guide
diff options
context:
space:
mode:
authort7yang <t7yang@gmail.com>2022-01-10 08:38:07 +0800
committerIrvin <irvinfly@gmail.com>2022-02-16 02:35:54 +0800
commit563ca0a35e98678e2b7d5f154f31f496851e8d60 (patch)
tree7c99e7e037128217eca2080df671a742076c615b /files/zh-cn/web/javascript/guide
parentd7b2995cabe8d85a1827aa18bc270bdf739f3d13 (diff)
downloadtranslated-content-563ca0a35e98678e2b7d5f154f31f496851e8d60.tar.gz
translated-content-563ca0a35e98678e2b7d5f154f31f496851e8d60.tar.bz2
translated-content-563ca0a35e98678e2b7d5f154f31f496851e8d60.zip
remove code tag inside pre tag for zh-CN
Diffstat (limited to 'files/zh-cn/web/javascript/guide')
-rw-r--r--files/zh-cn/web/javascript/guide/control_flow_and_error_handling/index.html4
-rw-r--r--files/zh-cn/web/javascript/guide/details_of_the_object_model/index.html2
-rw-r--r--files/zh-cn/web/javascript/guide/expressions_and_operators/index.html24
-rw-r--r--files/zh-cn/web/javascript/guide/functions/index.html28
-rw-r--r--files/zh-cn/web/javascript/guide/grammar_and_types/index.html8
5 files changed, 33 insertions, 33 deletions
diff --git a/files/zh-cn/web/javascript/guide/control_flow_and_error_handling/index.html b/files/zh-cn/web/javascript/guide/control_flow_and_error_handling/index.html
index aa26c47e83..5d7b3f356e 100644
--- a/files/zh-cn/web/javascript/guide/control_flow_and_error_handling/index.html
+++ b/files/zh-cn/web/javascript/guide/control_flow_and_error_handling/index.html
@@ -130,9 +130,9 @@ alert(x); // 输出的结果为 2
<p>请不要混淆原始的布尔值<code>true</code>和<code>false</code> 与 {{jsxref("Boolean")}}对象的真和假。例如:</p>
-<pre class="brush: js"><code class="language-js">var b = new Boolean(false);
+<pre class="brush: js">var b = new Boolean(false);
if (b) //结果视为真
-if (b == true) // 结果视为假</code></pre>
+if (b == true) // 结果视为假</pre>
<h4 id="示例_2"><strong>示例</strong></h4>
diff --git a/files/zh-cn/web/javascript/guide/details_of_the_object_model/index.html b/files/zh-cn/web/javascript/guide/details_of_the_object_model/index.html
index ef6ace35f4..ba337d158f 100644
--- a/files/zh-cn/web/javascript/guide/details_of_the_object_model/index.html
+++ b/files/zh-cn/web/javascript/guide/details_of_the_object_model/index.html
@@ -600,7 +600,7 @@ Employee.prototype.name = "Unknown";
<p>JavaScript 的属性查找机制首先在对象自身的属性中查找,如果指定的属性名称没有找到,将在对象的特殊属性 <code>__proto__</code> 中查找。这个过程是递归的;被称为“在原型链中查找”。</p>
-<p>特殊的 <code>__proto__</code> 属性是在构建对象时设置的;设置为构造器的 <code>prototype</code> 属性的值。所以表达式 <code>new Foo()</code> 将创建一个对象,其 <code>__proto__ == <code class="moz-txt-verticalline">Foo.prototype</code></code>。因而,修改 <code class="moz-txt-verticalline">Foo.prototype</code> 的属性,将改变所有通过 <code>new Foo()</code> 创建的对象的属性的查找。</p>
+<p>特殊的 <code>__proto__</code> 属性是在构建对象时设置的;设置为构造器的 <code>prototype</code> 属性的值。所以表达式 <code>new Foo()</code> 将创建一个对象,其 <code>__proto__ == <code>Foo.prototype</code></code>。因而,修改 <code>Foo.prototype</code> 的属性,将改变所有通过 <code>new Foo()</code> 创建的对象的属性的查找。</p>
<p>每个对象都有一个 <code>__proto__</code> 对象属性(除了 <code>Object);每个函数都有一个</code> <code>prototype</code> 对象属性。因此,通过“原型继承”,对象与其它对象之间形成关系。通过比较对象的 <code>__proto__</code> 属性和函数的 <code>prototype</code> 属性可以检测对象的继承关系。JavaScript 提供了便捷方法:<code>instanceof</code> 操作符可以用来将一个对象和一个函数做检测,如果对象继承自函数的原型,则该操作符返回真。例如:</p>
diff --git a/files/zh-cn/web/javascript/guide/expressions_and_operators/index.html b/files/zh-cn/web/javascript/guide/expressions_and_operators/index.html
index 8f45880006..bced40f16d 100644
--- a/files/zh-cn/web/javascript/guide/expressions_and_operators/index.html
+++ b/files/zh-cn/web/javascript/guide/expressions_and_operators/index.html
@@ -136,7 +136,7 @@ translation_of: Web/JavaScript/Guide/Expressions_and_Operators
<p>对于更复杂的赋值,<a href="https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment">解构赋值</a>语法是一个能从数组或对象对应的数组结构或对象字面量里提取数据的 Javascript 表达式。</p>
-<pre class="brush: js line-numbers language-js"><code class="language-js">var foo = ["one", "two", "three"];
+<pre class="brush: js line-numbers language-js">var foo = ["one", "two", "three"];
// 不使用解构
var one = foo[0];
@@ -144,14 +144,14 @@ var two = foo[1];
var three = foo[2];
// 使用解构
-var [one, two, three] = foo;</code></pre>
+var [one, two, three] = foo;</pre>
<h3 id="比较运算符">比较运算符</h3>
<p><a href="https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Operators/Comparison_Operators">比较运算符</a>比较它的操作数并返回一个基于表达式是否为真的逻辑值。操作数可以是数字,字符串,逻辑,对象值。字符串比较是基于标准的字典顺序,使用Unicode值。在多数情况下,如果两个操作数不是相同的类型, JavaScript 会尝试转换它们为恰当的类型来比较。这种行为通常发生在数字作为操作数的比较。类型转换的例外是使用 <code>===</code> 和 <code>!==</code> 操作符,它们会执行严格的相等和不相等比较。这些运算符不会在检查相等之前转换操作数的类型。下面的表格描述了该示例代码中的各比较运算符</p>
-<pre class="brush: js line-numbers language-js"><code class="language-js">var var1 = 3;
-var var2 = 4;</code></pre>
+<pre class="brush: js line-numbers language-js">var var1 = 3;
+var var2 = 4;</pre>
<table class="standard-table">
<caption>比较运算符</caption>
@@ -551,7 +551,7 @@ var n3 = !"Cat"; // !t returns false
<p>例如,</p>
-<pre class="brush: js line-numbers language-js"><code class="language-js">console.log("my " + "string"); // console logs the string "my string".</code></pre>
+<pre class="brush: js line-numbers language-js">console.log("my " + "string"); // console logs the string "my string".</pre>
<p>简写操作符 <code>+=</code> 也可以用来拼接字符串,例如:</p>
@@ -719,12 +719,12 @@ void expression
<p>如下创建了一个超链接文本,当用户单击该文本时,不会有任何效果。</p>
-<pre class="brush: html line-numbers language-html"><code class="language-html">&lt;a href="javascript:void(0)"&gt;Click here to do nothing&lt;/a&gt;</code></pre>
+<pre class="brush: html line-numbers language-html">&lt;a href="javascript:void(0)"&gt;Click here to do nothing&lt;/a&gt;</pre>
<p>下面的代码创建了一个超链接,当用户单击它时,提交一个表单。</p>
-<pre class="brush: html line-numbers language-html"><code class="language-html">&lt;a href="javascript:void(document.form.submit())"&gt;
-Click here to submit&lt;/a&gt;</code></pre>
+<pre class="brush: html line-numbers language-html">&lt;a href="javascript:void(document.form.submit())"&gt;
+Click here to submit&lt;/a&gt;</pre>
<h3 id="关系操作符">关系操作符</h3>
@@ -913,7 +913,7 @@ this.propertyName
<p>分组操作符()控制了表达式中计算的优先级. 举例来说, 你可以改变先乘除后加减的顺序,转而先计算加法。</p>
-<pre class="brush:js line-numbers language-js"><code class="language-js">var a = 1;
+<pre class="brush:js line-numbers language-js">var a = 1;
var b = 2;
var c = 3;
@@ -926,7 +926,7 @@ a + (b * c) // 7
(a + b) * c // 9
// 这等价于
-a * c + b * c // 9</code></pre>
+a * c + b * c // 9</pre>
<h5 id="数值推导">数值推导</h5>
@@ -941,12 +941,12 @@ a * c + b * c // 9</code></pre>
<p>Comprehensions特性被许多编程语言所采用,该特性能够使你快速地通过一个已有的数组来创建出一个新的数组,比如:</p>
-<pre class="brush:js line-numbers language-js"><code class="language-js">[for (i of [ 1, 2, 3 ]) i*i ];
+<pre class="brush:js line-numbers language-js">[for (i of [ 1, 2, 3 ]) i*i ];
// [ 1, 4, 9 ]
var abc = [ "A", "B", "C" ];
[for (letters of abc) letters.toLowerCase()];
-// [ "a", "b", "c" ]</code></pre>
+// [ "a", "b", "c" ]</pre>
<h3 id="左值表达式">左值表达式</h3>
diff --git a/files/zh-cn/web/javascript/guide/functions/index.html b/files/zh-cn/web/javascript/guide/functions/index.html
index f80d65ce3b..73a1efbdc4 100644
--- a/files/zh-cn/web/javascript/guide/functions/index.html
+++ b/files/zh-cn/web/javascript/guide/functions/index.html
@@ -85,7 +85,7 @@ console.log(factorial(3));
<p>下面的代码:</p>
-<pre class="brush: js line-numbers language-js"><code class="language-js">function map(f, a) {
+<pre class="brush: js line-numbers language-js">function map(f, a) {
let result = []; // 创建一个数组
let i; // 声明一个值,用来循环
for (i = 0; i != a.length; i++)
@@ -97,7 +97,7 @@ const f = function(x) {
}
let numbers = [0,1, 2, 5,10];
let cube = map(f,numbers);
-console.log(cube);</code></pre>
+console.log(cube);</pre>
<p>返回 [0, 1, 8, 125, 1000]。</p>
@@ -136,11 +136,11 @@ function square(n) { return n*n }
<p><strong>提示:</strong>注意只有使用如上的语法形式(即 <code>function funcName(){}</code>)才可以。而下面的代码是无效的。就是说,函数提升仅适用于函数声明,而不适用于函数表达式。</p>
</div>
-<pre class="brush: js example-bad line-numbers language-js"><code class="language-js">console.log(square); // square is hoisted with an initial value undefined.
+<pre class="brush: js example-bad line-numbers language-js">console.log(square); // square is hoisted with an initial value undefined.
console.log(square(5)); // Uncaught TypeError: square is not a function
const square = function (n) {
return n * n;
-}</code></pre>
+}</pre>
<p>函数的参数并不局限于字符串或数字。你也可以将整个对象传递给函数。函数 <code>show_props</code>(其定义参见 <a href="https://developer.mozilla.org/en-US/docs/JavaScript/Guide/Working_with_Objects#Objects_and_Properties" title="https://developer.mozilla.org/en-US/docs/JavaScript/Guide/Working_with_Objects#Objects_and_Properties">用对象编程</a>)就是一个将对象作为参数的例子。</p>
@@ -468,7 +468,7 @@ getCode(); // Returns the secret code
<p>例如,设想有一个用来连接字符串的函数。唯一事先确定的参数是在连接后的字符串中用来分隔各个连接部分的字符(译注:比如例子里的分号“;”)。该函数定义如下:</p>
-<pre class="brush: js line-numbers language-js"><code class="language-js">function myConcat(separator) {
+<pre class="brush: js line-numbers language-js">function myConcat(separator) {
var result = ''; // 把值初始化成一个字符串,这样就可以用来保存字符串了!!
var i;
// iterate through arguments
@@ -476,7 +476,7 @@ getCode(); // Returns the secret code
result += arguments[i] + separator;
}
return result;
-}</code></pre>
+}</pre>
<p>你可以给这个函数传递任意数量的参数,它会将各个参数连接成一个字符串“列表”:</p>
@@ -544,7 +544,7 @@ console.log(arr); // [2, 4, 6]</pre>
<p>在一些函数模式中,更简洁的函数很受欢迎。对比一下:</p>
-<pre class="brush: js line-numbers language-js"><code class="language-js">var a = [
+<pre class="brush: js line-numbers language-js">var a = [
"Hydrogen",
"Helium",
"Lithium",
@@ -557,13 +557,13 @@ console.log(a2); // logs [ 8, 6, 7, 9 ]
var a3 = a.map( s =&gt; s.length );
-console.log(a3); // logs [ 8, 6, 7, 9 ]</code></pre>
+console.log(a3); // logs [ 8, 6, 7, 9 ]</pre>
<h3 id="this_的词法"><code>this</code> 的词法</h3>
<p>在箭头函数出现之前,每一个新函数都重新定义了自己的 <a href="/zh-CN/docs/Web/JavaScript/Reference/Operators/this">this</a> 值(在构造函数中是一个新的对象;在严格模式下是未定义的;在作为“对象方法”调用的函数中指向这个对象;等等)。以面向对象的编程风格,这样着实有点恼人。</p>
-<pre class="brush: js line-numbers language-js"><code class="language-js">function Person() {
+<pre class="brush: js line-numbers language-js">function Person() {
// 构造函数Person()将`this`定义为自身
this.age = 0;
@@ -575,11 +575,11 @@ console.log(a3); // logs [ 8, 6, 7, 9 ]</code></pre>
}, 1000);
}
-var p = new Person();</code></pre>
+var p = new Person();</pre>
<p>在ECMAScript 3/5里,通过把<code>this</code>的值赋值给一个变量可以修复这个问题。</p>
-<pre class="brush: js line-numbers language-js"><code class="language-js">function Person() {
+<pre class="brush: js line-numbers language-js">function Person() {
var self = this; // 有的人习惯用`that`而不是`self`,
  // 无论你选择哪一种方式,请保持前后代码的一致性
self.age = 0;
@@ -588,13 +588,13 @@ var p = new Person();</code></pre>
// 以下语句可以实现预期的功能
self.age++;
}, 1000);
-}</code></pre>
+}</pre>
<p>另外,创建一个<a href="/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Function/bind">约束函数</a>可以使得 <code>this</code>值被正确传递给 <code>growUp()</code> 函数。</p>
<p>箭头函数捕捉闭包上下文的<code>this</code>值,所以下面的代码工作正常。</p>
-<pre class="brush: js line-numbers language-js"><code class="language-js">function Person(){
+<pre class="brush: js line-numbers language-js">function Person(){
this.age = 0;
setInterval(() =&gt; {
@@ -602,7 +602,7 @@ var p = new Person();</code></pre>
}, 1000);
}
-var p = new Person();</code></pre>
+var p = new Person();</pre>
<h2 id="预定义函数">预定义函数</h2>
diff --git a/files/zh-cn/web/javascript/guide/grammar_and_types/index.html b/files/zh-cn/web/javascript/guide/grammar_and_types/index.html
index 916abc0139..7fb7d70567 100644
--- a/files/zh-cn/web/javascript/guide/grammar_and_types/index.html
+++ b/files/zh-cn/web/javascript/guide/grammar_and_types/index.html
@@ -441,7 +441,7 @@ console.log(a[0]); // 3</pre>
<p>简言之,其语法是:</p>
-<pre class="brush: js"><code class="language-html">[(+|-)][digits][.digits][(E|e)[(+|-)]digits]</code></pre>
+<pre class="brush: js">[(+|-)][digits][.digits][(E|e)[(+|-)]digits]</pre>
<p>例如:</p>
@@ -495,7 +495,7 @@ console.log(unusualPropertyNames["!"]); // Bang!</pre>
<p>在ES2015,对象字面值扩展支持在创建时设置原型,简写了 foo: foo 形式的属性赋值,方法定义,支持父方法调用,以及使用表达式动态计算属性名。总之,这些也使对象字面值和类声明更加紧密地联系起来,让基于对象的设计从这些便利中更加受益。</p>
-<pre class="brush: js line-numbers language-js"><code class="language-js">var obj = {
+<pre class="brush: js line-numbers language-js">var obj = {
// __proto__
__proto__: theProtoObj,
// Shorthand for ‘handler: handler’
@@ -507,7 +507,7 @@ console.log(unusualPropertyNames["!"]); // Bang!</pre>
},
// Computed (dynamic) property names
[ 'prop_' + (() =&gt; 42)() ]: 42
-};</code></pre>
+};</pre>
<p>请注意:</p>
@@ -523,7 +523,7 @@ console.log(foo["2"]); // two</pre>
<p>一个正则表达式是字符被斜线(译注:正斜杠“/”)围成的表达式。下面是一个正则表达式文字的一个例子。</p>
-<pre class="brush: js line-numbers language-js"><code class="language-js">var re = /ab+c/;</code></pre>
+<pre class="brush: js line-numbers language-js">var re = /ab+c/;</pre>
<h3 id="字符串字面量_String_literals">字符串字面量 (String literals)</h3>