1.var name="the window";
var object={
name:"my object",
getNameFunc:function(){
return function(){
return this.name;
};
}
}
alert(object.getNameFunc()())
//無括號是返回function(){
return function(){
return this.name;
//一個括號返回function(){
return this.name;
//兩個括號返回the window
2.var name="the window";
var object={
name:"my object",
getNameFunc:function(){
var that=this;
return function(){
return that.name;
};
}
}
alert(object.getNameFunc()())
3.var name="the window";
var object={
name:"my object",
getNameFunc:function(){
return this;
};
}
}
alert(object.getNameFunc())
//SyntaxError: Unexpected token ;報錯
//字面量裏面多了一個分號,去掉後返回object object