语法高亮,滚动条美化,设置页面调整

This commit is contained in:
fofolee
2019-04-19 02:41:09 +08:00
parent 1e8f76c000
commit 359d29ee0b
1590 changed files with 12328 additions and 11441 deletions

View File

@@ -1,14 +1,14 @@
<article id="wikiArticle">
<div></div>
<h2 id="信息">信息</h2>
<pre class="syntaxbox">Firefox:
<pre><code class="language-javascript">Firefox:
句法错误: "use strict" 不允许在带默认参数的函数中
句法错误: "use strict" 不允许在带rest参数的函数中
句法错误: "use strict" 不允许在带解构参数的函数中
Chrome:
句法错误: 非法的'use strict'指令,在带有非简单参数列表的函数中
</pre>
</code></pre>
<h2 id="错误类型">错误类型</h2>
<p><a href="Reference/Global_Objects/SyntaxError" title="SyntaxError 对象代表尝试解析语法上不合法的代码的错误。"><code>SyntaxError</code></a>.</p>
<h2 id="哪里出错了">哪里出错了?</h2>
@@ -22,50 +22,50 @@ Chrome:
<h2 id="示例">示例</h2>
<h3 id="函数语句">函数语句</h3>
<p>在这种情况下函数sum具有默认参数a = 1和b = 2</p>
<pre class="brush: js example-bad">function sum(a=1, b=2) {
<pre><code class="language-js example-bad">function sum(a=1, b=2) {
// SyntaxError: "use strict" not allowed in function with default parameter
"use strict";
return a + b;
}
</pre>
</code></pre>
<p>如果这个函数应该处于 <a href="/en-US/docs/Web/JavaScript/Reference/Strict_mode">strict mode</a>,并且整个脚本或封装函数也可以在严格模式下,可以移动 "use strict" 指令到函数之外:</p>
<pre class="brush: js example-good">"use strict";
<pre><code class="language-js example-good">"use strict";
function sum(a=1, b=2) {
return a + b;
}
</pre>
</code></pre>
<h3 id="函数表达式">函数表达式</h3>
<p>函数表达式可以使用另一种解决方法:</p>
<pre class="brush: js example-bad">var sum = function sum([a, b]) {
<pre><code class="language-js example-bad">var sum = function sum([a, b]) {
// SyntaxError: "use strict" not allowed in function with destructuring parameter
"use strict";
return a + b;
};
</pre>
</code></pre>
<p>这可以转换为以下表达式:</p>
<pre class="brush: js example-good">var sum = (function() {
<pre><code class="language-js example-good">var sum = (function() {
"use strict";
return function sum([a, b]) {
return a + b;
};
})();
</pre>
</code></pre>
<h3 id="箭头函数">箭头函数</h3>
<p>如果箭头函数需要访问 <code>this</code>,则可以将箭头函数作为封闭函数来使用:</p>
<pre class="brush: js example-bad">var callback = (...args) =&gt; {
<pre><code class="language-js example-bad">var callback = (...args) =&gt; {
// SyntaxError: "use strict" not allowed in function with rest parameter
"use strict";
return this.run(args);
};
</pre>
</code></pre>
<p>这可以转换为以下表达式:</p>
<pre class="brush: js example-good">var callback = (() =&gt; {
<pre><code class="language-js example-good">var callback = (() =&gt; {
"use strict";
return (...args) =&gt; {
return this.run(args);
};
})();
</pre>
</code></pre>
<h2 id="也可以看看">也可以看看</h2>
<ul>
<li><a href="Reference/Strict_mode" title="如果你想改变你的代码让其工作在具有限制性JavaScript环境中请参阅转换成严格模式。">Strict mode</a></li>