摘要: 先看一段代码:var scope = "global"; function f() { console.log(scope); var scope = "local"; console.log(scope); }这段代码的输出结果是:undefined local js犀牛书上的解释是,与全局变量同名的局部变量在整个函数内部覆盖全局变量。简而言之,所有函数体内的变量声明(注意,仅仅是声明)都将被提到函数体开头进行。上述代码相当于以下代码的运行结果:var scope = "global"; function f() { var sco 阅读全文
posted @ 2011-07-31 12:48 yanng 阅读(251) 评论(0) 推荐(0) 编辑