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

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,9 +1,9 @@
<article id="wikiArticle">
<div></div>
<h2 id="错误提示">错误提示</h2>
<pre class="syntaxbox">SyntaxError: function statement requires a name [Firefox]
<pre><code class="language-javascript">SyntaxError: function statement requires a name [Firefox]
SyntaxError: Unexpected token ( [Chrome]
</pre>
</code></pre>
<h2 id="错误类型">错误类型</h2>
<p><a href="Reference/Global_Objects/SyntaxError" title="SyntaxError 对象代表尝试解析语法上不合法的代码的错误。"><code>SyntaxError</code></a></p>
<h2 id="哪里出错了?">哪里出错了?</h2>
@@ -11,44 +11,44 @@ SyntaxError: Unexpected token ( [Chrome]
<h2 id="示例">示例</h2>
<h3 id="语句与表达式">语句与表达式</h3>
<p><a href="/en-US/docs/Web/JavaScript/Reference/Statements/function">函数语句</a>(或函数声明)需要命名,以下写法是不正确的:</p>
<pre class="brush: js example-bad">function () {
<pre><code class="language-js example-bad">function () {
return 'Hello world';
}
// SyntaxError: function statement requires a name
</pre>
</code></pre>
<p>你可以使用<a href="/en-US/docs/Web/JavaScript/Reference/Operators/function">函数表达式</a>(赋值)来代替:</p>
<pre class="brush: js example-good">var greet = function() {
<pre><code class="language-js example-good">var greet = function() {
return 'Hello world';
};</pre>
};</code></pre>
<p>者是你想将其作为立即调用函数表达式(<a class="external" href="https://en.wikipedia.org/wiki/Immediately-invoked_function_expression" rel="noopener">IIFE</a>Immediately Invoked Function Expression也就是定义后立即执行的函数。在这种情况下你需要用到更多的括号</p>
<pre class="brush: js example-good">(function () {
<pre><code class="language-js example-good">(function () {
})();</pre>
})();</code></pre>
<h3 id="标号函数(Labeled_functions)">标号函数(Labeled functions)</h3>
<p>你使用函数标号(<a href="/en-US/docs/Web/JavaScript/Reference/Statements/label">labels)</a>的时候, 也需要在关键词 <code>function</code> 后面提供一个函数名称. 这样的代码是不能运行的:</p>
<pre class="brush: js example-bad">function Greeter() {
<pre><code class="language-js example-bad">function Greeter() {
german: function () {
return "Moin";
}
}
// SyntaxError: function statement requires a name
</pre>
</code></pre>
<p>这个例子可以正常运行:</p>
<pre class="brush: js example-good">function Greeter() {
<pre><code class="language-js example-good">function Greeter() {
german: function g() {
return "Moin";
}
}</pre>
}</code></pre>
<h3 id="对象方法">对象方法</h3>
<p>如果你想创建创建一个对象方法那么需要首先创建一个对象。以下语法function 关键字后面没有提供名称)是合法的:</p>
<pre class="brush: js example-good">var greeter = {
<pre><code class="language-js example-good">var greeter = {
german: function () {
return "Moin";
}
};</pre>
};</code></pre>
<h3 id="回调函数的语法">回调函数的语法</h3>
<p>另外,如果使用到了回调函数,那么检查一下语法是否正确。大括号与逗号很容易使情况变糟。</p>
<pre class="brush: js example-bad">promise.then(
<pre><code class="language-js example-bad">promise.then(
function() {
console.log("success");
});
@@ -56,9 +56,9 @@ SyntaxError: Unexpected token ( [Chrome]
console.log("error");
}
// SyntaxError: function statement requires a name
</pre>
</code></pre>
<p>正确的形式应该是这样的:</p>
<pre class="brush: json example-good">promise.then(
<pre><code class="language-json example-good">promise.then(
function() {
console.log("success");
},
@@ -66,7 +66,7 @@ SyntaxError: Unexpected token ( [Chrome]
console.log("error");
}
);
</pre>
</code></pre>
<h2 id="相关内容">相关内容</h2>
<ul>
<li><a href="/en-US/docs/Web/JavaScript/Guide/Functions">Functions in the JavaScript Guide</a></li>