diff options
author | Irvin <irvinfly@gmail.com> | 2022-02-16 02:07:31 +0800 |
---|---|---|
committer | Irvin <irvinfly@gmail.com> | 2022-02-16 02:35:54 +0800 |
commit | d9e9adb5f80a819fe46349bcf6d1faec734b09cd (patch) | |
tree | e856dc5e31aad0a7d5e8c2f98c9ee139d9569a86 /files/zh-cn/web/javascript/reference/strict_mode | |
parent | 7c2556fe79c44d7c31108b8c8b048d2b7704a95e (diff) | |
download | translated-content-d9e9adb5f80a819fe46349bcf6d1faec734b09cd.tar.gz translated-content-d9e9adb5f80a819fe46349bcf6d1faec734b09cd.tar.bz2 translated-content-d9e9adb5f80a819fe46349bcf6d1faec734b09cd.zip |
remove span tag in zh-CN
Diffstat (limited to 'files/zh-cn/web/javascript/reference/strict_mode')
-rw-r--r-- | files/zh-cn/web/javascript/reference/strict_mode/index.html | 6 | ||||
-rw-r--r-- | files/zh-cn/web/javascript/reference/strict_mode/transitioning_to_strict_mode/index.html | 4 |
2 files changed, 5 insertions, 5 deletions
diff --git a/files/zh-cn/web/javascript/reference/strict_mode/index.html b/files/zh-cn/web/javascript/reference/strict_mode/index.html index 0d9066e644..854e709953 100644 --- a/files/zh-cn/web/javascript/reference/strict_mode/index.html +++ b/files/zh-cn/web/javascript/reference/strict_mode/index.html @@ -35,7 +35,7 @@ translation_of: Web/JavaScript/Reference/Strict_mode <h2 id="调用严格模式">调用严格模式</h2> -<p>严格模式可以应用到<span id="noHighlight_0.9206554004884853">整个脚本</span>或个别函数中。不要在封闭大括弧 <code style="font-size: 14px;">{}</code> 内这样做,在这样的上下文中这么做是没有效果的<span style="line-height: 1.5;">。</span>在 <code style="font-size: 14px;">eval</code><span style="line-height: 1.5;"> 、</span><code style="font-size: 14px;">Function</code><span style="line-height: 1.5;"> 、内联事件处理属性、 </span> {{domxref("WindowTimers.setTimeout()")}} 方法中传入的脚本字符串,其行为类似于开启了严格模式的一个单独脚本<span id="noHighlight_0.9206554004884853">,它们会</span>如预期一样工作。</p> +<p>严格模式可以应用到整个脚本或个别函数中。不要在封闭大括弧 <code style="font-size: 14px;">{}</code> 内这样做,在这样的上下文中这么做是没有效果的。在 <code style="font-size: 14px;">eval</code> 、<code style="font-size: 14px;">Function</code> 、内联事件处理属性、 {{domxref("WindowTimers.setTimeout()")}} 方法中传入的脚本字符串,其行为类似于开启了严格模式的一个单独脚本,它们会如预期一样工作。</p> <h3 id="为脚本开启严格模式">为脚本开启严格模式</h3> @@ -164,7 +164,7 @@ with (obj) { // !!! 语法错误 } </pre> -<p><span style="line-height: 1.5;">一种取代 </span><code>with</code>的简单方法<span style="line-height: 1.5;">是,将目标对象赋给一个短命名变量,然后访问这个变量上的相应属性</span><span style="line-height: 1.5;">.</span></p> +<p>一种取代 <code>with</code>的简单方法是,将目标对象赋给一个短命名变量,然后访问这个变量上的相应属性.</p> <p>第二, <a class="external" href="http://whereswalden.com/2011/01/10/new-es5-strict-mode-support-new-vars-created-by-strict-mode-eval-code-are-local-to-that-code-only/"><code>严格模式下的 eval 不再为上层范围(surrounding scope,注:包围eval代码块的范围)引入新变量</code></a>. 在正常模式下, 代码 <code>eval("var x;")</code> 会给上层函数(surrounding function)或者全局引入一个新的变量 <code>x</code> . 这意味着, 一般情况下, 在一个包含 <code>eval</code> 调用的函数内所有没有引用到参数或者局部变量的名称都必须在运行时才能被映射到特定的定义 (因为 <code>eval</code> 可能引入的新变量会覆盖它的外层变量). 在严格模式下 <code>eval</code> 仅仅为被运行的代码创建变量, 所以 <code>eval</code> 不会使得名称映射到外部变量或者其他局部变量:</p> @@ -174,7 +174,7 @@ console.assert(x === 17); console.assert(evalX === 42); </pre> -<p>相应的, 如果函数 <code>eval</code> 被在严格模式下的<span style="font-family: courier new,andale mono,monospace; line-height: normal;"><code>eval(...)</code>以表达式的形式调用时</span><span style="line-height: 1.5;">, 其代码会被当做严格模式下的代码执行. 当然也可以在代码中显式开启严格模式, 但这样做并不是必须的.</span></p> +<p>相应的, 如果函数 <code>eval</code> 被在严格模式下的<code>eval(...)</code>以表达式的形式调用时, 其代码会被当做严格模式下的代码执行. 当然也可以在代码中显式开启严格模式, 但这样做并不是必须的.</p> <pre class="brush: js">function strict1(str) { "use strict"; diff --git a/files/zh-cn/web/javascript/reference/strict_mode/transitioning_to_strict_mode/index.html b/files/zh-cn/web/javascript/reference/strict_mode/transitioning_to_strict_mode/index.html index 8973075e47..740a018fb9 100644 --- a/files/zh-cn/web/javascript/reference/strict_mode/transitioning_to_strict_mode/index.html +++ b/files/zh-cn/web/javascript/reference/strict_mode/transitioning_to_strict_mode/index.html @@ -105,11 +105,11 @@ s.opacity = 1; <h4 id="arguments对象属性不与对应的形参变量同步更新"><code>arguments</code>对象属性不与对应的形参变量同步更新</h4> -<p>在非严格模式中,修改<code>arguments</code>对象中某个索引属性的值,和这个属性对应的形参变量的值也会同时变化,反之亦然.这会让JavaScript的代码混淆引擎让代码变得更难读和理解。在严格模式中<code><span style="font-family: courier,andale mono,monospace;">arguments 对象会以形参变量的拷贝的形式被创建和初始化,因此 arguments 对象的改变不会影响形参。</span></code></p> +<p>在非严格模式中,修改<code>arguments</code>对象中某个索引属性的值,和这个属性对应的形参变量的值也会同时变化,反之亦然.这会让JavaScript的代码混淆引擎让代码变得更难读和理解。在严格模式中<code>arguments 对象会以形参变量的拷贝的形式被创建和初始化,因此 arguments 对象的改变不会影响形参。</code></p> <h4 id="eval相关的区别"><code>eval相关的区别</code></h4> -<p>在严格模式中,<code>eval</code>不会在当前的作用域内创建新的变量.另外,传入eval的字符串参数也会按照严格模式来解析.你需要全面测试来确保没有代码收到影响。另外,<span style="font-family: courier,andale mono,monospace;">如果你并不是为了解决一个非常实际的解决方案中,</span>尽量不要使用<code>eval。</code></p> +<p>在严格模式中,<code>eval</code>不会在当前的作用域内创建新的变量.另外,传入eval的字符串参数也会按照严格模式来解析.你需要全面测试来确保没有代码收到影响。另外,如果你并不是为了解决一个非常实际的解决方案中,尽量不要使用<code>eval。</code></p> <h2 id="严格中立的代码">严格中立的代码</h2> |