例如:
var closure = (function(){
var closureVariable = "Localized";
function ReadLocal(){
//how can I access closureVariable here?
}
})();
例如:
var closure = (function(){
var closureVariable = "Localized";
function ReadLocal(){
//how can I access closureVariable here?
}
})();
只需使用closureVariable
.
例如:
var closure = (function(){
var closureVariable = "Localized";
function ReadLocal(){
console.log(closureVariable);
}
})();
ReadLocal
是一个内部作用域,局部变量在内部作用域中总是可见的。
你试过这个吗?
var closure = (function(){
var closureVariable = "Localized";
function ReadLocal(){
//how can I access closureVariable here?
console.log(closureVariable);
}
})();
closuserVariable 对 readLocal 来说是全局的,所以你可以访问它。