当前位置:编程学习 > JAVA >>

javascript闭包问题hezkvectory

 <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>
补充:web前端 , JavaScript ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,