闭包中怎么从内部函数访问外部函数的变量。如何访问外层函数呢?
var a = 1; function fun(){ var a = 2;//修改了全局作用域的a=2 function fun2(){ var a = 3; console.log(window.a);//2 console.log("访问外层函数的a:"); console.log(a);//3 } fun2(); } fun();
var a = 1;
function fun(){
var a = 2;//修改了全局作用域的a=2
function fun2(){
var a = 3;
console.log(window.a);//2
console.log("访问外层函数的a:");
console.log(a);//3
}
fun2();
fun();
pardon110
相关分类