考一下你对Javascript闭包的理解

小测试,有兴趣可以看下下面的两个代码分别输出什么

/*************************/

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


/***************************/
var name = "The Window";
  var object = {
    name : "My Object",
    getNameFunc : function(){
      var that = this;
      return function(){
        return that.name;
      };
    }
  };

  alert(object.getNameFunc()());


闭包资源:

1.学习Javascript闭包(Closure)

2.Javascript 闭包


你可能感兴趣的:(JavaScript,object,function,测试)