JavaScript/作用域:修订间差异

来自康健生活
Kangkk​(留言 | 贡献)
Kangkk​(留言 | 贡献)
第1行: 第1行:
== 引言 ==
== 引言 ==
== 作用域链 ==
== 作用域链 ==
=== 示例 ===
{{leftrightflex|<syntaxhighlight lang="javascript">
(function a() {
  var val = 'hello';
  (function b() {
    (function c() {
      val = 'world';
    })();
    console.log(val);
  })();
})();
</syntaxhighlight>|{{consoleout|<pre>
world</pre>}}}}
{{leftrightflex|<syntaxhighlight lang="javascript">
(function a() {
  var val = 'hello';
  (function b() {
    (function c() {
      window.val = 'world';
    })();
    console.log(val);
  })();
})();
</syntaxhighlight>|{{consoleout|<pre>
hello</pre>}}}}


== 示例 ==
== 示例 ==