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

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

@@ -5,11 +5,11 @@
<p><strong>块语句</strong>(或其他语言的<strong>复合语句</strong>)用于组合零个或多个语句。该块由一对大括号界定,可以是<a href="Reference/Statements/label" title="标记语句可以和 break 或 continue 语句一起使用。标记就是在一条语句前面加个可以引用的标识符。"><code>labelled</code></a></p>
<h2 id="语法">语法</h2>
<h3 id="块声明">块声明</h3>
<pre class="syntaxbox">{ <em>StatementList </em>}
</pre>
<pre><code class="language-javascript">{ <em>StatementList </em>}
</code></pre>
<h3 id="标记块声明">标记块声明</h3>
<pre class="syntaxbox"><em>LabelIdentifier</em>: { <em>StatementList </em>}
</pre>
<pre><code class="language-javascript"><em>LabelIdentifier</em>: { <em>StatementList </em>}
</code></pre>
<dl>
<dt><code>StatementList</code></dt>
<dd>在块语句中分组的语句。</dd>
@@ -21,30 +21,30 @@
<h3 id="块级作用域">块级作用域</h3>
<h4 id="使用var">使用<code>var</code></h4>
<p>通过<code>var</code>声明的变量<strong>没有</strong>块级作用域。在语句块里声明的变量作用域是其所在的函数或者 script 标签内,你可以在语句块外面访问到它。换句话说,语句块 不会生成一个新的作用域。尽管单独的语句块是合法的语句但在JavaScript中你不会想使用单独的语句块因为它们不像你想象的C或Java中的语句块那样处理事物。例如</p>
<pre class="brush: js example-bad">var x = 1;
<pre><code class="language-js example-bad">var x = 1;
{
var x = 2;
}
console.log(x); // 输出 2
</pre>
</code></pre>
<p>该会输出2因为块中的 <code>var x</code>语句与块前面的<code>var x</code>语句作用域相同。在 C 或 Java中这段代码会输出 1。</p>
<h4 id="使用let和_const">使用<code>let</code><code>const</code></h4>
<p>相比之下,使用 <a href="Reference/Statements/let" title="let允许你声明一个作用域被限制在块级中的变量、语句或者表达式。与var关键字不同的是var声明的变量只能是全局或者整个函数块的。"><code>let</code></a><a href="Reference/Statements/const" title="常量是块级作用域,很像使用 let 语句定义的变量。常量的值不能通过重新赋值来改变并且不能重新声明。"><code>const</code></a>声明的变量是<strong></strong>块级作用域的。</p>
<pre class="brush: js">let x = 1;
<pre><code class="language-javascript">let x = 1;
{
let x = 2;
}
console.log(x); // 输出 1</pre>
console.log(x); // 输出 1</code></pre>
<p><code>x = 2</code>被限制在块级作用域中, 也就是它被声明时所在的块级作用域。</p>
<p><code>const</code>的结果也是一样的:</p>
<pre class="brush: js">const c = 1;
<pre><code class="language-javascript">const c = 1;
{
const c = 2;
}
console.log(c); // 输出1, 而且不会报错</pre>
console.log(c); // 输出1, 而且不会报错</code></pre>
<p>注意块级作用域里的常量声明<code>const c = 2</code> 并不会抛出<code>SyntaxError: Identifier 'c' has already been declared</code>这样的语法错误,因为这是一个新的作用域。</p>
<h5 id="使用let声明的变量在块级作用域内能强制执行更新变量下面的两个例子对比">使用let声明的变量在块级作用域内能强制执行更新变量下面的两个例子对比</h5>
<pre class="brush: js">var a = [];
<pre><code class="language-javascript">var a = [];
for (<strong>var</strong> i = 0; i &lt; 10; i++) {
a[i] = function () {console.log(i);};
}
@@ -60,7 +60,7 @@ for (<strong>let</strong> i = 0; i &lt; 10; i++) {
}
a[0](); // 0
a[1](); // 1
a[6](); // 6</pre>
a[6](); // 6</code></pre>
<h4 id="使用function">使用<code>function</code></h4>
<p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function">函数声明</a>同样被限制在声明他的语句块内:</p>
<p> </p>
@@ -70,7 +70,7 @@ a[6](); // 6</pre>
console.log('foo is called ' + location);
}
foo('inside'); // 正常工作并且打印 'foo is called inside'
}</code></pre>
}</code></code></pre>
<p> </p>
<h2 id="规范">规范</h2>
<table class="standard-table">