0

例如:

var closure = (function(){
 var closureVariable = "Localized";

 function ReadLocal(){
  //how can I access closureVariable here?
 }
})();
4

2 回答 2

4

只需使用closureVariable.

例如:

var closure = (function(){
 var closureVariable = "Localized";

 function ReadLocal(){
  console.log(closureVariable);
 }
})();

ReadLocal是一个内部作用域,局部变量在内部作用域中总是可见的。

于 2012-08-13T23:34:54.857 回答
0

你试过这个吗?

var closure = (function(){
 var closureVariable = "Localized";

 function ReadLocal(){
  //how can I access closureVariable here?
   console.log(closureVariable);
 }
})();

closuserVariable 对 readLocal 来说是全局的,所以你可以访问它。

于 2012-08-13T23:35:02.953 回答