// var value = '1' // function foo(){ // console.log(value); // } // function bar(){ // var value = 2 // foo() // } // bar() // JavaScript 采用词法作用域(lexical scoping),也就是静态作用域。 var scope = "global scope"; function checkscope(){ var scope = "local scope"; function f(){ return scope; } return f(); } checkscope(); var scope = "global scope"; function checkscope(){ var scope = "local scope"; function f(){ return scope; } return f; } checkscope()();