当前位置: 代码迷 >> JavaScript >> javascript闭包有关问题
  详细解决方案

javascript闭包有关问题

热度:312   发布时间:2013-10-11 14:52:39.0
javascript闭包问题
  <script type="text/javascript">
window.onload = function(){
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()()); 
}
 </script>
  相关解决方案