diff options
author | t7yang <t7yang@gmail.com> | 2022-01-10 08:38:07 +0800 |
---|---|---|
committer | Irvin <irvinfly@gmail.com> | 2022-02-16 02:35:54 +0800 |
commit | 563ca0a35e98678e2b7d5f154f31f496851e8d60 (patch) | |
tree | 7c99e7e037128217eca2080df671a742076c615b /files/zh-cn/web | |
parent | d7b2995cabe8d85a1827aa18bc270bdf739f3d13 (diff) | |
download | translated-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')
46 files changed, 175 insertions, 177 deletions
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 b49d5c9024..1c4b9b7ab0 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 @@ -90,8 +90,8 @@ parseInt("010", 10); // 10 <p>一些老版本的浏览器会将首字符为“0”的字符串当做八进制数字,2013 年以前的 JavaScript 实现会返回一个意外的结果:</p> -<pre class="brush: js line-numbers language-js"><code class="language-js">parseInt("010"); // 8 -parseInt("0x10"); // 16</code></pre> +<pre class="brush: js line-numbers language-js">parseInt("010"); // 8 +parseInt("0x10"); // 16</pre> <p>这是因为字符串以数字 0 开头,{{jsxref("Global_Objects/parseInt", "parseInt()")}}函数会把这样的字符串视作八进制数字;同理,0x开头的字符串则视为十六进制数字。</p> @@ -104,9 +104,9 @@ parseInt("0x10"); // 16</code></pre> <p>一元运算符 + 也可以把数字字符串转换成数值:</p> -<pre class="brush: js line-numbers language-js"><code class="language-js">+ "42"; // 42 +<pre class="brush: js line-numbers language-js">+ "42"; // 42 + "010"; // 10 -+ "0x10"; // 16</code></pre> ++ "0x10"; // 16</pre> <p>如果给定的字符串不存在数值形式,函数会返回一个特殊的值 {{jsxref("NaN")}}(Not a Number 的缩写):</p> @@ -190,23 +190,23 @@ Boolean(234); // true <p><code><strong>let</strong></code> 语句声明一个块级作用域的本地变量,并且可选的将其初始化为一个值。</p> -<pre class="brush: js line-numbers language-js"><code class="language-js">let a; -let name = 'Simon';</code></pre> +<pre class="brush: js line-numbers language-js">let a; +let name = 'Simon';</pre> <p>下面是使用 <code><strong>let</strong></code> 声明变量作用域的例子:</p> -<pre class="brush: js line-numbers language-js"><code class="language-js">// myLetVariable 在这里 *不能* 被引用 +<pre class="brush: js line-numbers language-js">// myLetVariable 在这里 *不能* 被引用 for (let myLetVariable = 0; myLetVariable < 5; myLetVariable++) { // myLetVariable 只能在这里引用 } -// myLetVariable 在这里 *不能* 被引用</code></pre> +// myLetVariable 在这里 *不能* 被引用</pre> <p><code><strong>const</strong></code> 允许声明一个不可变的常量。这个常量在定义域内总是可见的。</p> -<pre class="brush: js line-numbers language-js"><code class="language-js">const Pi = 3.14; // 设置 Pi 的值 -Pi = 1; // 将会抛出一个错误因为你改变了一个常量的值。</code></pre> +<pre class="brush: js line-numbers language-js">const Pi = 3.14; // 设置 Pi 的值 +Pi = 1; // 将会抛出一个错误因为你改变了一个常量的值。</pre> <p><code><strong>var</strong></code> 是最常见的声明变量的关键字。它没有其他两个关键字的种种限制。这是因为它是传统上在 JavaScript 声明变量的唯一方法。使用 <strong><code>var</code></strong> 声明的变量在它所声明的整个函数都是可见的。</p> @@ -216,13 +216,13 @@ var name = "simon"; <p>一个使用 <strong><code>var</code> </strong>声明变量的语句块的例子:</p> -<pre class="brush: js line-numbers language-js"><code class="language-js">// myVarVariable在这里 *能* 被引用 +<pre class="brush: js line-numbers language-js">// myVarVariable在这里 *能* 被引用 for (var myVarVariable = 0; myVarVariable < 5; myVarVariable++) { - // myVarVariable 整个</code>函数<code class="language-js">中都能被引用 + // myVarVariable 整个函数中都能被引用 } -// myVarVariable 在这里 *能* 被引用</code></pre> +// myVarVariable 在这里 *能* 被引用</pre> <p>如果声明了一个变量却没有对其赋值,那么这个变量的类型就是 <code>undefined</code>。</p> @@ -302,15 +302,15 @@ do { <p>JavaScript 也还包括其他两种重要的 for 循环: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...of"><code>for</code>...<code>of</code></a></p> -<pre class="brush: js line-numbers language-js"><code class="language-js">for (let value of array) { +<pre class="brush: js line-numbers language-js">for (let value of array) { // do something with value -}</code></pre> +}</pre> <p>和 <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...in"><code>for</code>...<code>in</code></a> :</p> -<pre class="brush: js line-numbers language-js"><code class="language-js">for (let property in object) { +<pre class="brush: js line-numbers language-js">for (let property in object) { // do something with object property -}</code></pre> +}</pre> <p><code>&&</code> 和 <code>||</code> 运算符使用短路逻辑(short-circuit logic),是否会执行第二个语句(操作数)取决于第一个操作数的结果。在需要访问某个对象的属性时,使用这个特性可以事先检测该对象是否为空:</p> @@ -432,12 +432,12 @@ var name = obj.name; <p>和:</p> -<pre class="brush: js line-numbers language-js"><code class="language-js">// 括号表示法(bracket notation) +<pre class="brush: js line-numbers language-js">// 括号表示法(bracket notation) obj['name'] = 'Simon'; var name = obj['name']; // can use a variable to define a key var user = prompt('what is your key?') -obj[user] = prompt('what is its value?')</code></pre> +obj[user] = prompt('what is its value?')</pre> <p>这两种方法在语义上也是相同的。第二种方法的优点在于属性的名称被看作一个字符串,这就意味着它可以在运行时被计算,缺点在于这样的代码有可能无法在后期被解释器优化。它也可以被用来访问某些以<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#Keywords">预留关键字</a>作为名称的属性的值:</p> diff --git a/files/zh-cn/web/javascript/equality_comparisons_and_sameness/index.html b/files/zh-cn/web/javascript/equality_comparisons_and_sameness/index.html index c9e1e5ae71..06562c68b0 100644 --- a/files/zh-cn/web/javascript/equality_comparisons_and_sameness/index.html +++ b/files/zh-cn/web/javascript/equality_comparisons_and_sameness/index.html @@ -388,7 +388,7 @@ function attemptMutation(v) <dd> <p>显而易见,对<code>0一元负操作得到</code><code>-0</code>。但表达式的抽象化可能在你没有意识到得情况下导致-0延续传播。例如当考虑下例时:</p> - <pre class="brush:js language-js"><code class="language-js">let stoppingForce = obj.mass * -obj.velocity</code></pre> + <pre class="brush:js language-js">let stoppingForce = obj.mass * -obj.velocity</pre> <p>如果<code>obj.velocity</code>是<code>0</code> (或计算结果为<code>0</code>), <code>一个-0</code>就在上处产生并被赋值为<code>stoppingForce的值</code>.</p> </dd> diff --git a/files/zh-cn/web/javascript/eventloop/index.html b/files/zh-cn/web/javascript/eventloop/index.html index f9fdf69207..bb8dd97448 100644 --- a/files/zh-cn/web/javascript/eventloop/index.html +++ b/files/zh-cn/web/javascript/eventloop/index.html @@ -77,7 +77,7 @@ console.log(bar(7)); // 返回 42</pre> <p>下面的例子演示了这个概念(<code>setTimeout</code> 并不会在计时器到期之后直接执行):</p> -<pre class="brush: js line-numbers language-js"><code class="language-js">const s = new Date().getSeconds(); +<pre class="brush: js line-numbers language-js">const s = new Date().getSeconds(); setTimeout(function() { // 输出 "2",表示回调函数并没有在 500 毫秒之后立即执行 @@ -89,7 +89,7 @@ while(true) { console.log("Good, looped for 2 seconds"); break; } -}</code></pre> +}</pre> <h3 id="零延迟">零延迟</h3> 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"><a href="javascript:void(0)">Click here to do nothing</a></code></pre> +<pre class="brush: html line-numbers language-html"><a href="javascript:void(0)">Click here to do nothing</a></pre> <p>下面的代码创建了一个超链接,当用户单击它时,提交一个表单。</p> -<pre class="brush: html line-numbers language-html"><code class="language-html"><a href="javascript:void(document.form.submit())"> -Click here to submit</a></code></pre> +<pre class="brush: html line-numbers language-html"><a href="javascript:void(document.form.submit())"> +Click here to submit</a></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 => 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(() => { @@ -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_' + (() => 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> diff --git a/files/zh-cn/web/javascript/reference/errors/cant_assign_to_property/index.html b/files/zh-cn/web/javascript/reference/errors/cant_assign_to_property/index.html index 04853a2c53..e8b44ece57 100644 --- a/files/zh-cn/web/javascript/reference/errors/cant_assign_to_property/index.html +++ b/files/zh-cn/web/javascript/reference/errors/cant_assign_to_property/index.html @@ -8,7 +8,7 @@ original_slug: Web/JavaScript/Reference/Errors/不能添加属性 <h2 id="信息">信息</h2> -<pre class="syntaxbox">TypeError: <code class="highlighted" id="line-87">can't assign to property "x" on {y}: not an object</code> (Firefox) +<pre class="syntaxbox">TypeError: can't assign to property "x" on {y}: not an object (Firefox) TypeError: Cannot create property 'x' on {y} (Chrome) </pre> diff --git a/files/zh-cn/web/javascript/reference/errors/missing_semicolon_before_statement/index.html b/files/zh-cn/web/javascript/reference/errors/missing_semicolon_before_statement/index.html index 37c45bb0df..963008b259 100644 --- a/files/zh-cn/web/javascript/reference/errors/missing_semicolon_before_statement/index.html +++ b/files/zh-cn/web/javascript/reference/errors/missing_semicolon_before_statement/index.html @@ -61,15 +61,15 @@ array[0] = "there"; <p>如果你用的是另一种编程语言,那么在javaScript中使用不具有相同或完全没有意义的关键字也是很常见的:</p> -<pre class="brush: js example-bad line-numbers language-js"><code class="language-js">def print(info){ +<pre class="brush: js example-bad line-numbers language-js">def print(info){ console.log(info); -}; // SyntaxError missing ; before statement</code></pre> +}; // SyntaxError missing ; before statement</pre> <p>因此,建议使用<code>function</code>而不是<code>def</code>:</p> -<pre class="brush: js example-good line-numbers language-js"><code class="language-js">function print(info){ +<pre class="brush: js example-good line-numbers language-js">function print(info){ console.log(info); -};</code></pre> +};</pre> <p> </p> diff --git a/files/zh-cn/web/javascript/reference/functions/arguments/index.html b/files/zh-cn/web/javascript/reference/functions/arguments/index.html index 04d14b0b4f..b00da02c08 100644 --- a/files/zh-cn/web/javascript/reference/functions/arguments/index.html +++ b/files/zh-cn/web/javascript/reference/functions/arguments/index.html @@ -149,24 +149,24 @@ myConcat(". ", "sage", "basil", "oregano", "pepper", "parsley");</pre> <p>这个例子定义了一个函数通过一个字符串来创建HTML列表。这个函数唯一正式声明了的参数是一个字符。当该参数为 "<code>u</code>" 时,创建一个无序列表 (项目列表);当该参数为 "<code>o</code>" 时,则创建一个有序列表 (编号列表)。该函数定义如下:</p> -<pre class="brush:js language-js"><code class="language-js">function list(type) { +<pre class="brush:js language-js">function list(type) { var result = "<" + type + "l><li>"; var args = Array.prototype.slice.call(arguments, 1); result += args.join("</li><li>"); result += "</li></" + type + "l>"; // end list return result; -}</code></pre> +}</pre> <p>你可以传递任意数量的参数到该函数,并将每个参数作为一个项添加到指定类型的列表中。例如:</p> -<pre class="brush:js language-js"><code class="language-js">var listHTML = list("u", "One", "Two", "Three"); +<pre class="brush:js language-js">var listHTML = list("u", "One", "Two", "Three"); /* listHTML is: "<ul><li>One</li><li>Two</li><li>Three</li></ul>" -*/</code> +*/ </pre> <h3 id="剩余参数、默认参数和解构赋值参数">剩余参数、默认参数和解构赋值参数</h3> diff --git a/files/zh-cn/web/javascript/reference/global_objects/array/flat/index.html b/files/zh-cn/web/javascript/reference/global_objects/array/flat/index.html index f6a9420e21..4f06aff1fc 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/array/flat/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/array/flat/index.html @@ -78,16 +78,14 @@ const flattened = arr => [].concat(...arr);</code></pre> <h3 class="brush: js" id="reduce_concat_isArray_recursivity">reduce + concat + isArray + recursivity</h3> -<pre class="brush: js"><code>// 使用 reduce、concat 和递归展开无限多层嵌套的数组 -var arr1 = [1,2,3,[1,2,3,4, [2,3,4]]]; -</code> -<code class="language-js">function flatDeep(arr, d = 1) { +<pre class="brush: js">// 使用 reduce、concat 和递归展开无限多层嵌套的数组 + var arr1 = [1,2,3,[1,2,3,4, [2,3,4]]]; +function flatDeep(arr, d = 1) { return d > 0 ? arr.reduce((acc, val) => acc.concat(Array.isArray(val) ? flatDeep(val, d - 1) : val), []) : arr.slice(); -};</code> -<code> +}; flatDeep(arr1, Infinity); -// [1, 2, 3, 1, 2, 3, 4, 2, 3, 4]</code></pre> +// [1, 2, 3, 1, 2, 3, 4, 2, 3, 4]</pre> <h3 id="forEachisArraypushrecursivity">forEach+isArray+push+recursivity</h3> diff --git a/files/zh-cn/web/javascript/reference/global_objects/array/length/index.html b/files/zh-cn/web/javascript/reference/global_objects/array/length/index.html index 8f17e9af1f..de5862921d 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/array/length/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/array/length/index.html @@ -82,25 +82,25 @@ function printEntries(arr) { <p>下面的例子中,通过数组下标遍历数组元素,并把每个元素的值修改为原值的2倍。</p> -<pre class="brush: js line-numbers language-js"><code class="language-js">var numbers = [1, 2, 3, 4, 5]; +<pre class="brush: js line-numbers language-js">var numbers = [1, 2, 3, 4, 5]; var length = numbers.length; for (var i = 0; i < length; i++) { numbers[i] *= 2; } -// 遍历后的结果 [2, 4, 6, 8, 10]</code></pre> +// 遍历后的结果 [2, 4, 6, 8, 10]</pre> <h3 id="Example:_Shortening_an_array" name="Example:_Shortening_an_array">截断数组</h3> <p>下面的例子中,如果数组长度大于 3,则把该数组的长度截断为 3 。</p> -<pre class="brush: js line-numbers language-js"><code class="language-js">var numbers = [1, 2, 3, 4, 5]; +<pre class="brush: js line-numbers language-js">var numbers = [1, 2, 3, 4, 5]; if (numbers.length > 3) { numbers.length = 3; } console.log(numbers); // [1, 2, 3] -console.log(numbers.length); // 3</code></pre> +console.log(numbers.length); // 3</pre> <h2 id="规范">规范</h2> diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/getdate/index.html b/files/zh-cn/web/javascript/reference/global_objects/date/getdate/index.html index 5f7d438415..57f12998f6 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/date/getdate/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/date/getdate/index.html @@ -13,7 +13,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Date/getDate <h2 id="Syntax" name="Syntax">语法</h2> -<pre class="syntaxbox language-html"><code class="language-html">dateObj.getDate()</code></pre> +<pre class="syntaxbox language-html">dateObj.getDate()</pre> <h2 id="Parameters" name="Parameters">参数</h2> @@ -29,10 +29,10 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Date/getDate <p>下面第二条语句将值25赋给 day 变量,该值基于日期对象 <code>Xmax95</code>的值。</p> -<pre class="brush:js language-js"><code class="language-js">var Xmas95 = new Date("December 25, 1995 23:15:00"); +<pre class="brush:js language-js">var Xmas95 = new Date("December 25, 1995 23:15:00"); var day = Xmas95.getDate(); -alert(day); // 25</code></pre> +alert(day); // 25</pre> <h2 id="规范">规范</h2> diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/getday/index.html b/files/zh-cn/web/javascript/reference/global_objects/date/getday/index.html index b2ee4a80cd..584180a8fb 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/date/getday/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/date/getday/index.html @@ -13,7 +13,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Date/getDay <h2 id="Syntax" name="Syntax">语法</h2> -<pre class="syntaxbox language-html"><code class="language-html"><em>dateObj</em>.getDay()</code> +<pre class="syntaxbox language-html"><em>dateObj</em>.getDay() </pre> <h3 id="Description" name="Description">返回值</h3> @@ -26,10 +26,10 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Date/getDay <p>下面第二条语句,基于{{jsxref("Date")}}对象 <code>Xmas95</code> 的值,把 1 赋值给 <code>weekday</code>。也就是说1995年12月25日是星期一。</p> -<pre class="brush:js language-js"><code class="language-js">var Xmas95 = new Date("December 25, 1995 23:15:30"); +<pre class="brush:js language-js">var Xmas95 = new Date("December 25, 1995 23:15:30"); var weekday = Xmas95.getDay(); -console.log(weekday); // 1</code></pre> +console.log(weekday); // 1</pre> <div class="blockIndicator note"> <p dir="ltr">注意:如果需要,可以使用{{jsxref("DateTimeFormat", "Intl.DateTimeFormat")}}与一个额外的<code>options</code> 参数,从而返回这天的全称(如<code>"Monday"</code>).使用此方法,结果会更加国际化:</p> diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/getfullyear/index.html b/files/zh-cn/web/javascript/reference/global_objects/date/getfullyear/index.html index 6b8638c52d..c29a10aa45 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/date/getfullyear/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/date/getfullyear/index.html @@ -21,7 +21,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Date/getFullYear <h2 id="Syntax" name="Syntax">语法</h2> -<pre><code class="language-html">dateObj.getFullYear()</code> +<pre class="brush: html">dateObj.getFullYear() </pre> <h3 id="Description" name="Description">返回值</h3> diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/gethours/index.html b/files/zh-cn/web/javascript/reference/global_objects/date/gethours/index.html index fda9396354..62d35dd713 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/date/gethours/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/date/gethours/index.html @@ -29,10 +29,10 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Date/getHours <p>下面第二条语句,基于日期对象 <code>Xmas95 </code>的值,把 23 赋值给了变量 <code>hours。</code></p> -<pre class="brush:js language-js"><code class="language-js">var Xmas95 = new Date("December 25, 1995 23:15:00"); +<pre class="brush:js language-js">var Xmas95 = new Date("December 25, 1995 23:15:00"); var hours = Xmas95.getHours(); -alert(hours); // 23</code></pre> +alert(hours); // 23</pre> <h2 id="规范">规范</h2> diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/getmilliseconds/index.html b/files/zh-cn/web/javascript/reference/global_objects/date/getmilliseconds/index.html index c5dd09e3d9..2cbc0b9d30 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/date/getmilliseconds/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/date/getmilliseconds/index.html @@ -29,9 +29,9 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Date/getMilliseconds <p>下例中,将当前时间的毫秒数赋值给变量 <code>ms</code>。</p> -<pre class="brush: js language-js"><code class="language-js">var ms; +<pre class="brush: js language-js">var ms; Today = new Date(); -ms = Today.getMilliseconds();</code></pre> +ms = Today.getMilliseconds();</pre> <h2 id="规范">规范</h2> diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/getminutes/index.html b/files/zh-cn/web/javascript/reference/global_objects/date/getminutes/index.html index 8322a9e813..a27f4c265d 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/date/getminutes/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/date/getminutes/index.html @@ -11,7 +11,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Date/getMinutes <h2 id="Syntax" name="Syntax">语法</h2> -<pre class="syntaxbox language-html"><code class="language-html">dateObj.getMinutes()</code></pre> +<pre class="syntaxbox language-html">dateObj.getMinutes()</pre> <h3 id="Parameters" name="Parameters">参数</h3> @@ -27,8 +27,8 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Date/getMinutes <p>下例中,第二行语句运行过后,变量 <code>minutes </code>的值为15,也就是说 <code>Xmas95 </code>这个日期对象的值为某时15分某秒。</p> -<pre class="brush:js language-js"><code class="language-js">var Xmas95 = new Date("December 25, 1995 23:15:00"); -var minutes = Xmas95.getMinutes();</code></pre> +<pre class="brush:js language-js">var Xmas95 = new Date("December 25, 1995 23:15:00"); +var minutes = Xmas95.getMinutes();</pre> <p dir="ltr"><strong>规范</strong></p> diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/getseconds/index.html b/files/zh-cn/web/javascript/reference/global_objects/date/getseconds/index.html index ded6203208..1cb80b2ea8 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/date/getseconds/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/date/getseconds/index.html @@ -13,7 +13,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Date/getSeconds <h2 id="Syntax" name="Syntax">语法</h2> -<pre class="syntaxbox language-html"><code class="language-html">dateObj.getSeconds()</code></pre> +<pre class="syntaxbox language-html">dateObj.getSeconds()</pre> <h3 id="Parameters" name="Parameters">参数</h3> @@ -29,8 +29,8 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Date/getSeconds <p>下面第二条语句,基于日期对象 <code>Xmas95</code> 的值,把 30 赋值给变量 <code>secs</code>。</p> -<pre class="brush:js language-js"><code class="language-js">var Xmas95 = new Date("December 25, 1995 23:15:30"); -var secs = Xmas95.getSeconds();</code></pre> +<pre class="brush:js language-js">var Xmas95 = new Date("December 25, 1995 23:15:30"); +var secs = Xmas95.getSeconds();</pre> <div class="line-number"> </div> diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/gettimezoneoffset/index.html b/files/zh-cn/web/javascript/reference/global_objects/date/gettimezoneoffset/index.html index 7ee056a7df..90b7d1a962 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/date/gettimezoneoffset/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/date/gettimezoneoffset/index.html @@ -13,7 +13,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Date/getTimezoneOffset <h2 id="Syntax" name="Syntax">语法</h2> -<pre class="syntaxbox language-html"><code class="language-html">dateObj.getTimezoneOffset()</code></pre> +<pre class="syntaxbox language-html">dateObj.getTimezoneOffset()</pre> <h3 id="Parameters" name="Parameters">参数</h3> diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/parse/index.html b/files/zh-cn/web/javascript/reference/global_objects/date/parse/index.html index 68a8d136e7..5b0a6cf01d 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/date/parse/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/date/parse/index.html @@ -70,26 +70,26 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Date/parse <p>但是, 在如 ECMA-262 规范中定义的情况,如果因为无效值而导致日期字符串不能被识别为 ISO 格式时,根据浏览器和给定的值不同,返回值可以是,也可以不是 {{jsxref("NaN")}} 。比如:</p> -<pre class="brush: js line-numbers language-js"><code class="language-js">// 包含无效值的非 ISO 格式字符串 -new Date('23/25/2014');</code></pre> +<pre class="brush: js line-numbers language-js">// 包含无效值的非 ISO 格式字符串 +new Date('23/25/2014');</pre> <p>在 Firefox 30 中会被识别为本地时区的2015年12月25日,而在 Safari 7 中则是无效日期。但是,如果字符串被识别为 ISO 格式并且包含无效值,则在所有遵循 ES5 或者更新标准的浏览器中都会返回 {{jsxref("NaN")}} 。</p> -<pre class="brush: js line-numbers language-js"><code class="language-js">// 包含无效值的 ISO 格式字符串 +<pre class="brush: js line-numbers language-js">// 包含无效值的 ISO 格式字符串 new Date('2014-25-23').toISOString(); -// 在所有遵循 ES5的浏览器中返回 "RangeError: invalid date"</code></pre> +// 在所有遵循 ES5的浏览器中返回 "RangeError: invalid date"</pre> <p>SpiderMonkey 的引擎策略可以在 <a href="http://mxr.mozilla.org/mozilla-central/source/js/src/jsdate.cpp?rev=64553c483cd1#889"><code>jsdate.cpp</code></a> 中找到。字符串 <code>"10 06 2014"</code> 可以作为非 ISO 格式字符串使用自定义处理方式的例子。参见这篇关于解析如何进行的<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1023155#c6">粗略纲要</a>。</p> -<pre class="brush: js line-numbers language-js"><code class="language-js">new Date('10 06 2014');</code></pre> +<pre class="brush: js line-numbers language-js">new Date('10 06 2014');</pre> <p>将会被解析为本地时间 2014年10月6日,而不是6月10日。另一个例子</p> -<pre class="brush: js line-numbers language-js"><code class="language-js">new Date('foo-bar 2014').toString(); +<pre class="brush: js line-numbers language-js">new Date('foo-bar 2014').toString(); // 返回: "Invalid Date" Date.parse('foo-bar 2014'); -// 返回: NaN</code></pre> +// 返回: NaN</pre> <h2 id="Examples" name="Examples">例子</h2> @@ -97,7 +97,7 @@ Date.parse('foo-bar 2014'); <p>如果 <code>IPOdate</code> 是一个已经存在的 {{jsxref("Date")}} 对象,则可以把其设置为本地时间 1995年8月9日。如下:</p> -<pre class="brush: js line-numbers language-js"><code class="language-js">IPOdate.setTime(Date.parse('Aug 9, 1995'));</code></pre> +<pre class="brush: js line-numbers language-js">IPOdate.setTime(Date.parse('Aug 9, 1995'));</pre> <p>其他一些解析非标准格式日期的例子:</p> diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/setfullyear/index.html b/files/zh-cn/web/javascript/reference/global_objects/date/setfullyear/index.html index c8fcb530ab..e5693e9e07 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/date/setfullyear/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/date/setfullyear/index.html @@ -13,7 +13,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Date/setFullYear <h2 id="Syntax" name="Syntax">语法</h2> -<pre class="syntaxbox language-html"><code class="language-html">dateObj.setFullYear(yearValue[, monthValue[, dayValue]])</code></pre> +<pre class="syntaxbox language-html">dateObj.setFullYear(yearValue[, monthValue[, dayValue]])</pre> <h3 id="Parameters" name="Parameters">参数</h3> @@ -36,8 +36,8 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Date/setFullYear <h3 id="Example:_Using_setFullYear" name="Example:_Using_setFullYear">例子:使用<code>setFullYear</code>方法</h3> -<pre class="brush:js language-js"><code class="language-js">var theBigDay = new Date(); -theBigDay.setFullYear(1997);</code></pre> +<pre class="brush:js language-js">var theBigDay = new Date(); +theBigDay.setFullYear(1997);</pre> <h2 id="规范">规范</h2> diff --git a/files/zh-cn/web/javascript/reference/global_objects/infinity/index.html b/files/zh-cn/web/javascript/reference/global_objects/infinity/index.html index f20755f907..929985516d 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/infinity/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/infinity/index.html @@ -25,11 +25,11 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Infinity <h2 id="示例">示例</h2> -<pre class="brush: js line-numbers language-js"><code class="language-js">console.log(Infinity ); /* Infinity */ +<pre class="brush: js line-numbers language-js">console.log(Infinity ); /* Infinity */ console.log(Infinity + 1 ); /* Infinity */ console.log(Math.pow(10, 1000)); /* Infinity */ console.log(Math.log(0) ); /* -Infinity */ -console.log(1 / Infinity ); /* 0 */</code></pre> +console.log(1 / Infinity ); /* 0 */</pre> <h2 id="规范">规范</h2> diff --git a/files/zh-cn/web/javascript/reference/global_objects/isfinite/index.html b/files/zh-cn/web/javascript/reference/global_objects/isfinite/index.html index e69904ba41..cea70e68ee 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/isfinite/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/isfinite/index.html @@ -33,7 +33,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/isFinite <h2 id="Examples" name="Examples">示例</h2> -<pre class="brush: js language-js"><code class="language-js">isFinite(Infinity); // false +<pre class="brush: js language-js">isFinite(Infinity); // false isFinite(NaN); // false isFinite(-Infinity); // false @@ -41,7 +41,7 @@ isFinite(0); // true isFinite(2e64); // true, 在更强壮的Number.isFinite(null)中将会得到false -isFinite("0"); // true, 在更强壮的Number.isFinite('0')中将会得到false</code></pre> +isFinite("0"); // true, 在更强壮的Number.isFinite('0')中将会得到false</pre> <div class="line-number"> </div> diff --git a/files/zh-cn/web/javascript/reference/global_objects/isnan/index.html b/files/zh-cn/web/javascript/reference/global_objects/isnan/index.html index fac7d74714..1e23c1d0e4 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/isnan/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/isnan/index.html @@ -48,10 +48,10 @@ translation_of: Web/JavaScript/Reference/Global_Objects/isNaN <p>一个<code>isNaN</code>的 polyfill 可以理解为(这个polyfill利用了<code>NaN</code>自身永不相等于自身这一特征 ):</p> -<pre class="brush: js line-numbers language-js"><code class="language-js">var isNaN = function(value) { +<pre class="brush: js line-numbers language-js">var isNaN = function(value) { var n = Number(value); return n !== n; -};</code></pre> +};</pre> <h2 id="Examples" name="Examples">示例</h2> diff --git a/files/zh-cn/web/javascript/reference/global_objects/math/pi/index.html b/files/zh-cn/web/javascript/reference/global_objects/math/pi/index.html index fcfc82fbd5..efc463d5b7 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/math/pi/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/math/pi/index.html @@ -23,11 +23,11 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Math/PI <p>下面的函数使用 Math.PI 计算给定半径的圆周长:</p> -<pre class="brush:js language-js"><code class="language-js">function calculateCircumference (radius) { +<pre class="brush:js language-js">function calculateCircumference (radius) { return 2 * Math.PI * radius; } -calculateCircumference(1); // 6.283185307179586</code></pre> +calculateCircumference(1); // 6.283185307179586</pre> <h2 id="规范">规范</h2> 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 91796ae506..04602b2699 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 @@ -50,11 +50,11 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Math/random <p>这个例子返回了一个在指定值之间的随机整数。这个值不小于 <code>min</code> (如果 <code>min</code> 不是整数,则不小于 <code>min</code> 的向上取整数),且小于(不等于)<code>max</code>。</p> -<pre class="brush: js line-numbers language-js"><code class="language-js">function getRandomInt(min, max) { +<pre class="brush: js line-numbers language-js">function getRandomInt(min, max) { min = Math.ceil(min); max = Math.floor(max); - return Math.floor(Math.random() * (max - min)) + min; </code>//不含最大值,含最小值<code class="language-js"> -}</code></pre> + return Math.floor(Math.random() * (max - min)) + min; //不含最大值,含最小值 +}</pre> <div class="note"> <p>也许很容易想到用 <code>Math.round()</code> 来实现,但是这会导致你的随机数处于一个不均匀的分布,这可能不符合你的需求。</p> @@ -64,11 +64,11 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Math/random <p>上一个例子提到的函数 <code>getRandomInt()</code> 结果范围包含了最小值,但不含最大值。如果你的随机结果需要同时包含最小值和最大值,怎么办呢? <code>getRandomIntInclusive()</code> 函数可以实现。</p> -<pre class="brush: js line-numbers language-js"><code class="language-js">function getRandomIntInclusive(min, max) { +<pre class="brush: js line-numbers language-js">function getRandomIntInclusive(min, max) { min = Math.ceil(min); max = Math.floor(max); return Math.floor(Math.random() * (max - min + 1)) + min; //含最大值,含最小值 -}</code></pre> +}</pre> <h2 id="规范">规范</h2> diff --git a/files/zh-cn/web/javascript/reference/global_objects/math/sign/index.html b/files/zh-cn/web/javascript/reference/global_objects/math/sign/index.html index 60808dde44..590089e3c1 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/math/sign/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/math/sign/index.html @@ -50,12 +50,12 @@ Math.sign(); // NaN <h2 id="Compatibility" name="Compatibility">Polyfill</h2> -<pre class="brush: js language-js"><code class="language-js">function sign(x) { +<pre class="brush: js language-js">function sign(x) { x = +x ;// convert to a number if (x === 0 || isNaN(x)) return x; return x > 0 ? 1 : -1; -}</code></pre> +}</pre> <p> </p> diff --git a/files/zh-cn/web/javascript/reference/global_objects/object/getownpropertydescriptors/index.html b/files/zh-cn/web/javascript/reference/global_objects/object/getownpropertydescriptors/index.html index cc321fa788..22df48a042 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/object/getownpropertydescriptors/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/object/getownpropertydescriptors/index.html @@ -41,14 +41,14 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDes <p>创建子类的典型方法是定义子类,将其原型设置为超类的实例,然后在该实例上定义属性。这么写很不优雅,特别是对于 getters 和 setter 而言。 相反,您可以使用此代码设置原型:</p> -<pre class="brush: js line-numbers language-js"><code class="language-js">function superclass() {} +<pre class="brush: js line-numbers language-js">function superclass() {} superclass.prototype = { // 在这里定义方法和属性 }; function subclass() {} subclass.prototype = Object.create(superclass.prototype, Object.getOwnPropertyDescriptors({ // 在这里定义方法和属性 -}));</code></pre> +}));</pre> <h2 id="规范">规范</h2> diff --git a/files/zh-cn/web/javascript/reference/global_objects/object/valueof/index.html b/files/zh-cn/web/javascript/reference/global_objects/object/valueof/index.html index e2627097bd..82d2bc61d9 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/object/valueof/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/object/valueof/index.html @@ -147,7 +147,7 @@ console.log( str2.valueOf() === str2 ); // false</pre> <h3 id="改写_.prototype.valueof">改写 .prototype.valueof</h3> -<pre class="brush: js line-numbers language-js"><code class="language-js">function MyNumberType(n) { +<pre class="brush: js line-numbers language-js">function MyNumberType(n) { this.number = n; } @@ -156,7 +156,7 @@ MyNumberType.prototype.valueOf = function() { }; var myObj = new MyNumberType(4); -myObj + 3; // 7</code></pre> +myObj + 3; // 7</pre> <h2 id="规范">规范</h2> diff --git a/files/zh-cn/web/javascript/reference/global_objects/parsefloat/index.html b/files/zh-cn/web/javascript/reference/global_objects/parsefloat/index.html index 21d4e0bfbd..f32b3bbf90 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/parsefloat/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/parsefloat/index.html @@ -55,13 +55,13 @@ translation_of: Web/JavaScript/Reference/Global_Objects/parseFloat <p>下面的例子都返回<strong>3.14</strong></p> -<pre class="brush: js line-numbers language-js"><code class="language-js">parseFloat(3.14); +<pre class="brush: js line-numbers language-js">parseFloat(3.14); parseFloat('3.14'); parseFloat(' 3.14 '); parseFloat('314e-2'); parseFloat('0.0314E+2'); parseFloat('3.14some non-digit characters'); -parseFloat({ toString: function() { return "3.14" } });</code></pre> +parseFloat({ toString: function() { return "3.14" } });</pre> <h3 id="parseFloat返回NaN"><code>parseFloat</code>返回NaN</h3> @@ -74,8 +74,8 @@ parseFloat({ toString: function() { return "3.14" } });</code></pre> <p>以下例子均返回 <code>900719925474099300</code>,当整数太大以至于不能被转换时将失去精度。</p> -<pre class="brush: js line-numbers language-js"><code class="language-js">parseFloat(900719925474099267n); -parseFloat('900719925474099267n');</code></pre> +<pre class="brush: js line-numbers language-js">parseFloat(900719925474099267n); +parseFloat('900719925474099267n');</pre> <h2 id="规范">规范</h2> diff --git a/files/zh-cn/web/javascript/reference/global_objects/set/has/index.html b/files/zh-cn/web/javascript/reference/global_objects/set/has/index.html index 0bbad115ec..47369b1f27 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/set/has/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/set/has/index.html @@ -35,7 +35,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Set/has <h3 id="Example:_Testing_size_of_all_array_elements" name="Example:_Testing_size_of_all_array_elements">使用 <code>has</code> 方法</h3> -<pre class="brush: js line-numbers language-js"><code class="language-js">var mySet = new Set(); +<pre class="brush: js line-numbers language-js">var mySet = new Set(); mySet.add('foo'); mySet.has('foo'); // 返回 true @@ -47,7 +47,7 @@ set1.add(obj1); set1.has(obj1); // 返回 true set1.has({'key1': 1}); // 会返回 false,因为其是另一个对象的引用 -set1.add({'key1': 1}); // 现在 set1 中有2条(不同引用的)对象了</code></pre> +set1.add({'key1': 1}); // 现在 set1 中有2条(不同引用的)对象了</pre> <h2 id="规范">规范</h2> diff --git a/files/zh-cn/web/javascript/reference/global_objects/string/match/index.html b/files/zh-cn/web/javascript/reference/global_objects/string/match/index.html index 33a3a57880..f369a7a7f9 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/string/match/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/string/match/index.html @@ -60,7 +60,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/match <p>在下例中,使用 <code>match</code> 查找 "<code>Chapter</code>" 紧跟着 1 个或多个数值字符,再紧跟着一个小数点和数值字符 0 次或多次。正则表达式包含 <code>i</code> 标志,因此大小写会被忽略。</p> -<pre class="brush: js line-numbers language-js"><code class="language-js">var str = 'For more information, see Chapter 3.4.5.1'; +<pre class="brush: js line-numbers language-js">var str = 'For more information, see Chapter 3.4.5.1'; var re = /see (chapter \d+(\.\d)*)/i; var found = str.match(re); @@ -76,30 +76,30 @@ console.log(found); // 'Chapter 3.4.5.1' 被'(chapter \d+(\.\d)*)'捕获。 // '.1' 是被'(\.\d)'捕获的最后一个值。 // 'index' 属性(22) 是整个匹配从零开始的索引。 -// 'input' 属性是被解析的原始字符串。</code></pre> +// 'input' 属性是被解析的原始字符串。</pre> <h3 id="Example_Using_global_and_ignore_case_flags_with_match" name="Example:_Using_global_and_ignore_case_flags_with_match">例子:<code>match</code> 使用全局(global)和忽略大小写(ignore case)标志</h3> <p>下例展示了 <code>match</code> 使用 global 和 ignore case 标志。A-E、a-e 的所有字母将会作为一个数组的元素返回。</p> -<pre class="brush: js line-numbers language-js"><code class="language-js">var str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; +<pre class="brush: js line-numbers language-js">var str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; var regexp = /[A-E]/gi; var matches_array = str.match(regexp); console.log(matches_array); -// ['A', 'B', 'C', 'D', 'E', 'a', 'b', 'c', 'd', 'e']</code></pre> +// ['A', 'B', 'C', 'D', 'E', 'a', 'b', 'c', 'd', 'e']</pre> <h3 id="使用match,不传参数"><code>使用match(),不传参数 </code></h3> -<pre class="brush: js line-numbers language-js"><code class="language-js">var str = "Nothing will come of nothing."; +<pre class="brush: js line-numbers language-js">var str = "Nothing will come of nothing."; -str.match(); // returns [""]</code></pre> +str.match(); // returns [""]</pre> <h3 id="一个非正则表达式对象作为参数">一个非正则表达式对象作为参数</h3> <p>当参数是一个字符串或一个数字,它会使用new RegExp(obj)来隐式转换成一个 {{jsxref("RegExp")}}。如果它是一个有正号的正数,RegExp() 方法将忽略正号。</p> -<pre class="brush: js line-numbers language-js"><code class="language-js">var str1 = "NaN means not a number. Infinity contains -Infinity and +Infinity in JavaScript.", +<pre class="brush: js line-numbers language-js">var str1 = "NaN means not a number. Infinity contains -Infinity and +Infinity in JavaScript.", str2 = "My grandfather is 65 years old and My grandmother is 63 years old.", str3 = "The contract was declared null and void."; str1.match("number"); // "number" 是字符串。返回["number"] @@ -109,7 +109,7 @@ str1.match(+Infinity); // 返回["Infinity"] str1.match(-Infinity); // 返回["-Infinity"] str2.match(65); // 返回["65"] str2.match(+65); // 有正号的number。返回["65"] -str3.match(null); // 返回["null"]</code></pre> +str3.match(null); // 返回["null"]</pre> <h2 id="规范">规范</h2> diff --git a/files/zh-cn/web/javascript/reference/global_objects/string/padstart/index.html b/files/zh-cn/web/javascript/reference/global_objects/string/padstart/index.html index 98d0f201ed..c358da2585 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/string/padstart/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/string/padstart/index.html @@ -35,17 +35,17 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/padStart <h2 id="示例">示例</h2> -<pre class="brush: js line-numbers language-js"><code class="language-js">'abc'.padStart(10); // " abc" +<pre class="brush: js line-numbers language-js">'abc'.padStart(10); // " abc" 'abc'.padStart(10, "foo"); // "foofoofabc" 'abc'.padStart(6,"123465"); // "123abc" 'abc'.padStart(8, "0"); // "00000abc" -'abc'.padStart(1); // "abc"</code></pre> +'abc'.padStart(1); // "abc"</pre> <h2 id="Polyfill">Polyfill</h2> <p>如果原生环境不支持该方法,在其他代码之前先运行下面的代码,将创建 <code>String.prototype.padStart()</code> 方法。</p> -<pre class="brush: js line-numbers language-js"><code class="language-js">// https://github.com/uxitten/polyfill/blob/master/string.polyfill.js +<pre class="brush: js line-numbers language-js">// https://github.com/uxitten/polyfill/blob/master/string.polyfill.js // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padStart if (!String.prototype.padStart) { String.prototype.padStart = function padStart(targetLength,padString) { @@ -62,7 +62,7 @@ if (!String.prototype.padStart) { return padString.slice(0,targetLength) + String(this); } }; -}</code> +} </pre> <h2 id="规范">规范</h2> diff --git a/files/zh-cn/web/javascript/reference/global_objects/string/repeat/index.html b/files/zh-cn/web/javascript/reference/global_objects/string/repeat/index.html index c0ee77fe21..e412b0da5c 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/string/repeat/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/string/repeat/index.html @@ -44,7 +44,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/repeat <p>此方法已添加到 ECMAScript 2015 规范中,并且可能尚未在所有 JavaScript 实现中可用。然而,你可以使用以下代码段对 String.prototype.repeat() 进行填充:</p> -<pre class="brush: js language-js"><code class="language-js">if (!String.prototype.repeat) { +<pre class="brush: js language-js">if (!String.prototype.repeat) { String.prototype.repeat = function(count) { 'use strict'; if (this == null) { @@ -83,7 +83,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/repeat } return rpt; } -}</code></pre> +}</pre> <h2 id="Examples" name="Examples">示例</h2> diff --git a/files/zh-cn/web/javascript/reference/global_objects/string/tolowercase/index.html b/files/zh-cn/web/javascript/reference/global_objects/string/tolowercase/index.html index 7db9f1e146..e8fd231457 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/string/tolowercase/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/string/tolowercase/index.html @@ -15,7 +15,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/toLowerCase <h2 id="语法">语法</h2> -<pre class="syntaxbox language-html"><code class="language-html">str.toLowerCase()</code> +<pre class="syntaxbox language-html">str.toLowerCase() </pre> <h3 id="返回值">返回值</h3> diff --git a/files/zh-cn/web/javascript/reference/global_objects/symbol/index.html b/files/zh-cn/web/javascript/reference/global_objects/symbol/index.html index fce5989dd7..38506cf5f0 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/symbol/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/symbol/index.html @@ -150,9 +150,9 @@ typeof symObj; // "object"</pre> <p> {{jsxref("Operators/typeof", "typeof")}}运算符能帮助你识别 symbol 类型</p> -<pre class="brush: js"><code class="language-js">typeof Symbol() === 'symbol' +<pre class="brush: js">typeof Symbol() === 'symbol' typeof Symbol('foo') === 'symbol' -typeof Symbol.iterator === 'symbol'</code> +typeof Symbol.iterator === 'symbol' </pre> <h3 id="Symbol_类型转换">Symbol 类型转换</h3> @@ -170,7 +170,7 @@ typeof Symbol.iterator === 'symbol'</code> <p>Symbols 在 <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...in"><code>for...in</code></a> 迭代中不可枚举。另外,{{jsxref("Object.getOwnPropertyNames()")}} 不会返回 symbol 对象的属性,但是你能使用 {{jsxref("Object.getOwnPropertySymbols()")}} 得到它们。</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 = {}; obj[Symbol("a")] = "a"; obj[Symbol.for("b")] = "b"; @@ -179,14 +179,14 @@ obj.d = "d"; for (var i in obj) { console.log(i); // logs "c" and "d" -}</code></pre> +}</pre> <h3 id="Symbols_与_JSON.stringify">Symbols 与 <code>JSON.stringify()</code></h3> <p>当使用 JSON.stringify() 时,以 symbol 值作为键的属性会被完全忽略:</p> -<pre class="brush: js"><code class="language-js">JSON.stringify({[Symbol("foo")]: "foo"}); -// '{}'</code></pre> +<pre class="brush: js">JSON.stringify({[Symbol("foo")]: "foo"}); +// '{}'</pre> <p>更多细节,请看 {{jsxref("JSON.stringify()")}}。</p> @@ -194,10 +194,10 @@ for (var i in obj) { <p>当一个 Symbol 包装器对象作为一个属性的键时,这个对象将被强制转换为它包装过的 symbol 值:</p> -<pre class="brush: js"><code class="language-js">var sym = Symbol("foo"); +<pre class="brush: js">var sym = Symbol("foo"); var obj = {[sym]: 1}; obj[sym]; // 1 -obj[Object(sym)]; // still 1</code></pre> +obj[Object(sym)]; // still 1</pre> <h2 id="规范">规范</h2> diff --git a/files/zh-cn/web/javascript/reference/global_objects/undefined/index.html b/files/zh-cn/web/javascript/reference/global_objects/undefined/index.html index 20ff8d53a7..2748581673 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/undefined/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/undefined/index.html @@ -101,9 +101,9 @@ if(y === undefined) { // ReferenceError: y is not defined <p>但是,技术方面看来这样的使用方法应该被避免。JavaScript是一个静态作用域语言,所以,一个变量是否被声明可以通过看它是否在一个封闭的上下文中被声明。唯一的例外是全局作用域,但是全局作用域是被绑定在全局对象上的,所以要检查一个变量是否在全局上下文中存在可以通过检查全局对象上是否存在这个属性(比如使用{{jsxref("Operators/in", "in")}}操作符)。</p> -<pre class="brush: js line-numbers language-js"><code class="language-js">if ('x' in window) { +<pre class="brush: js line-numbers language-js">if ('x' in window) { // 只有x被全局性的定义 才会这行这些语句 -}</code></pre> +}</pre> <h3 id="Void操作符和undefined">Void操作符和undefined</h3> diff --git a/files/zh-cn/web/javascript/reference/global_objects/webassembly/index.html b/files/zh-cn/web/javascript/reference/global_objects/webassembly/index.html index 87978a0016..5ce3af745f 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/webassembly/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/webassembly/index.html @@ -63,10 +63,10 @@ translation_of: Web/JavaScript/Reference/Global_Objects/WebAssembly <p>下面的示例(请参见GitHub上的<a href="https://github.com/mdn/webassembly-examples/blob/master/js-api-examples/instantiate-streaming.html">Instantiate-streaming.html</a>演示,并查看<a href="https://mdn.github.io/webassembly-examples/js-api-examples/instantiate-streaming.html">在线演示</a>)直接从流式底层源传输.wasm模块,然后对其进行编译和实例化,并通过<code>ResultObject</code>实现promise。 由于<code>instantiateStreaming()</code>函数接受对 {{domxref("Response")}} 对象的promise,因此您可以直接向其传递{{domxref("WindowOrWorkerGlobalScope.fetch()")}}调用,然后它将把返回的response传递给随后的函数。</p> -<pre class="brush: js line-numbers language-js"><code class="language-js">var importObject = { imports: { imported_func: arg => console.log(arg) } }; +<pre class="brush: js line-numbers language-js">var importObject = { imports: { imported_func: arg => console.log(arg) } }; WebAssembly.instantiateStreaming(fetch('simple.wasm'), importObject) -.then(obj => obj.instance.exports.exported_func())</code></pre> +.then(obj => obj.instance.exports.exported_func())</pre> <p>返回的<code>ResultObject</code>实例的成员可以被随后访问到,可以调用实例中被导出的方法。</p> diff --git a/files/zh-cn/web/javascript/reference/statements/break/index.html b/files/zh-cn/web/javascript/reference/statements/break/index.html index c0297dbb86..a15c0bf7d9 100644 --- a/files/zh-cn/web/javascript/reference/statements/break/index.html +++ b/files/zh-cn/web/javascript/reference/statements/break/index.html @@ -33,7 +33,7 @@ translation_of: Web/JavaScript/Reference/Statements/break <p>下面的函数里有个 <code>break</code> 语句,当 <code>i</code> 为 3 时,会中止 {{jsxref("Statements/while", "while")}} 循环,然后返回 3 * <code>x</code> 的值。</p> -<pre class="brush: js"><code class="language-js">function testBreak(x) { +<pre class="brush: js">function testBreak(x) { var i = 0; while (i < 6) { @@ -44,7 +44,7 @@ translation_of: Web/JavaScript/Reference/Statements/break } return i * x; -}</code></pre> +}</pre> <h3 id="break_in_switch_statements">break in switch statements</h3> diff --git a/files/zh-cn/web/javascript/reference/statements/continue/index.html b/files/zh-cn/web/javascript/reference/statements/continue/index.html index ce08e7f444..8d58c28a2b 100644 --- a/files/zh-cn/web/javascript/reference/statements/continue/index.html +++ b/files/zh-cn/web/javascript/reference/statements/continue/index.html @@ -43,7 +43,7 @@ translation_of: Web/JavaScript/Reference/Statements/continue <p>下述例子展示了一个在<code>i</code> 为 3时执行<code>continue</code> 语句的 {{jsxref("Statements/while", "while")}} 循环。因此,<code>n</code> 的值在几次迭代后分别为 1, 3, 7 和 12 .</p> -<pre class="brush: js language-js"><code class="language-js">i = 0; +<pre class="brush: js language-js">i = 0; n = 0; while (i < 5) { i++; @@ -51,7 +51,7 @@ while (i < 5) { continue; } n += i; -}</code></pre> +}</pre> <h3 id="使用带_label_的_continue">使用带 label 的 continue</h3> @@ -61,7 +61,7 @@ while (i < 5) { <p>参考 {{jsxref("Statements/label", "label")}} 。</p> -<pre class="brush: js language-js"><code class="language-js">var i = 0, +<pre class="brush: js language-js">var i = 0, j = 8; checkiandj: while (i < 4) { @@ -77,11 +77,11 @@ checkiandj: while (i < 4) { } console.log("i = " + i); console.log("j = " + j); -}</code></pre> +}</pre> <p>输出:</p> -<pre class="brush: js language-js"><code class="language-js">"i: 0" +<pre class="brush: js language-js">"i: 0" // start checkj "j: 8" @@ -105,7 +105,7 @@ checkiandj: while (i < 4) { "i: 3" "i = 4" -"j = 4"</code></pre> +"j = 4"</pre> <h2 id="规范">规范</h2> diff --git a/files/zh-cn/web/javascript/reference/statements/debugger/index.html b/files/zh-cn/web/javascript/reference/statements/debugger/index.html index 0018dc056c..0f07a5b799 100644 --- a/files/zh-cn/web/javascript/reference/statements/debugger/index.html +++ b/files/zh-cn/web/javascript/reference/statements/debugger/index.html @@ -19,10 +19,10 @@ translation_of: Web/JavaScript/Reference/Statements/debugger <p>下面的例子演示了一个包含 debugger 语句的函数,当函数被调用时,会尝试调用一个可用的调试器进行调试。</p> -<pre class="brush:js language-js"><code class="language-js">function potentiallyBuggyCode() { +<pre class="brush:js language-js">function potentiallyBuggyCode() { debugger; // do potentially buggy stuff to examine, step through, etc. -}</code></pre> +}</pre> <p>当 debugger 被调用时, 执行暂停在 debugger 语句的位置。就像在脚本源代码中的断点一样。</p> diff --git a/files/zh-cn/web/javascript/reference/statements/do...while/index.html b/files/zh-cn/web/javascript/reference/statements/do...while/index.html index 89a850f722..614ef2ad4b 100644 --- a/files/zh-cn/web/javascript/reference/statements/do...while/index.html +++ b/files/zh-cn/web/javascript/reference/statements/do...while/index.html @@ -37,17 +37,17 @@ while (<em>condition</em>); <h3 id="HTML_内容">HTML 内容</h3> -<pre class="brush: html line-numbers language-html"><code class="language-html"><div id="example"></div></code></pre> +<pre class="brush: html line-numbers language-html"><div id="example"></div></pre> <h3 id="JavaScript_内容">JavaScript 内容</h3> -<pre class="brush: js"><code class="language-js">var result = ''; +<pre class="brush: js">var result = ''; var i = 0; do { i += 1; result += i + ' '; } while (i < 5); -document.getElementById('example').innerHTML = result;</code></pre> +document.getElementById('example').innerHTML = result;</pre> <h3 id="结果">结果</h3> diff --git a/files/zh-cn/web/javascript/reference/statements/function/index.html b/files/zh-cn/web/javascript/reference/statements/function/index.html index be8920fca8..ef61d65141 100644 --- a/files/zh-cn/web/javascript/reference/statements/function/index.html +++ b/files/zh-cn/web/javascript/reference/statements/function/index.html @@ -96,23 +96,23 @@ if (true) { <p>JavaScript 中的<strong>函数声明</strong>被提升到了<strong>函数定义</strong>。你可以在函数声明之前使用该函数:</p> -<pre class="brush: js language-js"><code class="language-js">hoisted(); // logs "foo" +<pre class="brush: js language-js">hoisted(); // logs "foo" function hoisted() { console.log('foo'); -}</code> +} </pre> <div class="note"> <p>注意 :<strong>函数表达式</strong>{{jsxref("Operators/function", "function expressions")}} 不会被提升:</p> </div> -<pre class="brush: js language-js"><code class="language-js">notHoisted(); // TypeError: notHoisted is not a function +<pre class="brush: js language-js">notHoisted(); // TypeError: notHoisted is not a function var notHoisted = function() { console.log('bar'); }; -</code></pre> +</pre> <h2 id="Examples" name="Examples">示例</h2> @@ -120,9 +120,9 @@ var notHoisted = function() { <p>下面的代码声明了一个函数,该函数返回了销售的总金额, 参数是产品a,b,c分别的销售的数量.</p> -<pre class="brush: js language-js"><code class="language-js">function calc_sales(units_a, units_b, units_c) {functionfunctionfunctionfunctionfunctionfunctionfunctionfunctionfunctionfunctionfunction +<pre class="brush: js language-js">function calc_sales(units_a, units_b, units_c) {functionfunctionfunctionfunctionfunctionfunctionfunctionfunctionfunctionfunctionfunction return units_a*79 + units_b * 129 + units_c * 699; -}</code></pre> +}</pre> <h2 id="规范">规范</h2> diff --git a/files/zh-cn/web/javascript/reference/template_literals/index.html b/files/zh-cn/web/javascript/reference/template_literals/index.html index f6dcc23c02..dbd08899c1 100644 --- a/files/zh-cn/web/javascript/reference/template_literals/index.html +++ b/files/zh-cn/web/javascript/reference/template_literals/index.html @@ -170,14 +170,14 @@ tag`string text line 1 \n string text line 2`; <p>另外,使用{{jsxref("String.raw()")}} 方法创建原始字符串和使用默认模板函数和字符串连接创建是一样的。</p> -<pre class="brush: js line-numbers language-js"><code class="language-js">var str = String.raw`Hi\n${2+3}!`;var`Hi\n${2+3} +<pre class="brush: js line-numbers language-js">var str = String.raw`Hi\n${2+3}!`;var`Hi\n${2+3} // "Hi\\n5!" str.length;. // 6 str.split('').join(',');. -// "H,i,\\,n,5,!"</code> +// "H,i,\\,n,5,!" </pre> <h3 id="带标签的模版字面量及转义序列">带标签的模版字面量及转义序列</h3> |