Can the getNameFun
function just return this.name
instead of an anonymous function? Is there a reason for this structure?
Code Segment 1:
var name = "The Window";
var object = {
name : "My Object",
getNameFunc : function(){
return function(){
return this.name;
};
}
};
alert(object.getNameFunc()());
Code Segment 2:
var name = "The Window";
var object = {
name : "My Object",
getNameFunc : function(){
return this.name; // difference is here!
}
};
alert(object.getNameFunc());