解决方案 »

  1.   

    没问题啊,你objects.getNameFunc()返回的是一个匿名函数啊。又直接在window下面执行,就是the window了呗。
      

  2.   

    var name = "The Window";   
      var objects = 
        {  
        name : "My Object",  
        getNameFunc:function()
            {  
              var me=this;
          return function(){  
            return me.name;  
           };   
        }   
        }; 
        console.log(objects);
        console.log(objects.getNameFunc()()); 
      

  3.   

        <script type="text/javascript">
        // 闭包运行机制
      var name = "The Window";   
      var objects = 
        {  
        name : "My Object",  
        getNameFunc:function()//这个function是objects对象的方法
            {  
    //this在每个function作用域中都是独立的
    var _this=this;//这里的this指向objects对象
          return function(){//这个function不是objects对象的方法
            alert(this.name);//这里的this指向window对象
            alert(_this.name);
           };   
        }   
        }; 
    objects.getNameFunc()(); 
        </script>
      

  4.   

    给你拆解一下你就明白
    objects.getNameFunc()()
    实际上他是等于下面代码
    var test = objects.getNameFunc();
    test();而objects.getNameFunc() 实际上是等于function (){return this.name;  }
    因此得出  test = function (){return this.name;  }
    那么很容易就知道 这个时候 this 指向的是windows 了.
      

  5.   

    楼上几位的解释都对~     
    1.objects.getNameFunc()执行完后得到的是一个匿名函数   getNameFunc是objects的属性  但是这个函数不是objects的属性 
    2.this关键字是不能在函数之间传递的  所以匿名函数也不会引用到外层函数(getNameFunc)的this即objects
    3.当一个函数不作为某个对象方法调用的时候  它的this是默认指向window的