javascript閉梱[二つの小さいテスト例]

748 ワード

プログラム1
<script>
var name = "The Window";
var Object_a = {
  name : "My Object",
  getNameFunc : function(){
               var that = this;
    return function(){
      return that.name;
    };
  }
};
alert(Object_a.getNameFunc()());
</script>
 
結果:My Object
 
二.プログラム二
<script>
var name = "The Window";
var Object_a = {
  name : "My Object",
  getNameFunc : function(){
    return function(){
      return this.name;
    };
  }
};
alert(Object_a.getNameFunc()());
</script>
 
結果:The Window