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

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

@@ -25,30 +25,30 @@
<h3 id="新的运行时错误">新的运行时错误</h3>
<p>JavaScript曾经会在一些上下文的某些情况中静默的失败严格模式会在这些情况下抛出错误。如果你的代码包含这样的场景请务必测试以确保没有代码受到影响。再说一次严格模式是可以设置在代码粒度下的。</p>
<h4 id="给一个未声明的变量赋值">给一个未声明的变量赋值</h4>
<pre class="brush: js">function f(x){
<pre><code class="language-javascript">function f(x){
"use strict";
var a = 12;
b = a + x*35; // error!
}
f();
</pre>
</code></pre>
<p>改变一个全局对象的值可能会造成不可预期的后果。如果你真的想设置一个全局对象的值,把他作为一个参数并且明确的把它作为一个属性:</p>
<pre class="brush: js">var global = this; // in the top-level context, "this" always refers the global object
<pre><code class="language-javascript">var global = this; // in the top-level context, "this" always refers the global object
function f(){
"use strict";
var a = 12;
global.b = a + x*35;
}
f();
</pre>
</code></pre>
<h4 id="尝试删除一个不可配置的属性">尝试删除一个不可配置的属性</h4>
<pre class="brush: js">"use strict";
<pre><code class="language-javascript">"use strict";
delete Object.prototype; // error!
</pre>
</code></pre>
<p>在非严格模式中,这样的代码只会静默失败,这样可能会导致用户误以为删除操作成功了.</p>
<h4 id="arguments对象和函数属性">arguments对象和函数属性</h4>
<p>在严格模式下,访问<code>arguments.callee</code>, <code>arguments.caller</code>, <code>anyFunction.caller</code>以及<code>anyFunction.arguments</code>都会抛出异常.唯一合法的使用应该是在其中命名一个函数并且重用之</p>
<pre class="brush: js">// example taken from vanillajs: http://vanilla-js.com/
<pre><code class="language-javascript">// example taken from vanillajs: http://vanilla-js.com/
var s = document.getElementById('thing').style;
s.opacity = 1;
(function(){
@@ -56,9 +56,9 @@ s.opacity = 1;
s.display="none";
else
setTimeout(arguments.callee, 40);
})();</pre>
})();</code></pre>
<p>可以重新写成:</p>
<pre class="brush: js">"use strict";
<pre><code class="language-javascript">"use strict";
var s = document.getElementById('thing').style;
s.opacity = 1;
(function fadeOut(){ // name the function
@@ -66,7 +66,7 @@ s.opacity = 1;
s.display="none";
else
setTimeout(fadeOut, 40); // use the name of the function
})();</pre>
})();</code></pre>
<h3 id="语义差异">语义差异</h3>
<p>这些差异都是一些微小的差异。有可能单元测试没办法捕获这种微小的差异。你很有必要去小心地审查你的代码,来确保这些差异不会影响你代码的语义。幸运的是,这种小心地代码审查可以逐函数地完成。</p>
<h4 id="函数调用中的this">函数调用中的<code>this</code></h4>