日期:2014-05-16  浏览次数:20433 次

js闭包的疑问
<script>
var name = "The Window";
  var object = {
    name : "My Object",
    getNameFunc : function(){
      return function(){
        return this.name;
      };
    }
  };
  alert(object.getNameFunc()());
</script>  




上面结果为The Window

<script>
var name = "The Window";
  var object = {
    name : "My Object",
    getNameFunc : function(){
      var that = this;
      return function(){
        return that.name;
      };
    }
  };
  alert(object.getNameFunc()());

</script>


上面结果为My Object



疑问一:第一段代码怎么能访问到外面的nane
疑问二:alert(object.getNameFunc()()) ,为什么要两个括号?