/*面试一*/
//代码片段一 没有闭包
var name ="the Window"
var object ={
name : "my object",
getNameFunc: function(){
return function(){
return this.name;
}
}
}
alert(object.getNameFunc()()) //the Window
//代码片段二 有闭包
var name2="the Window"
var object2 ={
name : "my object",
getNameFunc: function(){
var that = this
return function(){
return that.name
}
}
}
alert(object2.getNameFunc()()) //my object