js closure??

<script>
     var name = "The Window";
     var object = {
    name : "My Object",

    getNameFunc : function(){
                            console.log("11111");
                            console.log( this );   // this == object // the object that calls the anonymous function 
      return  function (){
                              console.log("22222");
                              console.log( this ); // this == window //Anonymous function under anonymous function 
      return  this .name;
      };
    }

  };
  alert(object.getNameFunc()());
        
        
        //--
  var name = "The Window";

  var object = {
    name : "My Object",

    getNameFunc : function(){
      var that = this;
      return function(){
                      console.log("33333");
                       console.log(this); //this==window
                      console.log("44444");
                       console.log(that); //that==object
        return that.name;
      };

    }

  };

  alert(object.getNameFunc()());
    </script>

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325027187&siteId=291194637