7. Question 1
var name = "The Window";
var object = {
name : "My Object",
getNameFunc : function(){
return function(){
return this.name;
};
}
};
console.log(object.getNameFunc()());
8. Question 2
var name = "The Window";
var object = {
name : "My Object",
getNameFunc : function(){
return function(){
return name;
};
}
};
console.log(object.getNameFunc()());
13. Double Confirm
var name = "The Window";
var object = {
name : "My Object",
getNameFunc : function(){
return function(){
return this.name;
};
}
};
window.onload = object.getNameFunc;
15. Solution 1
var name = "The Window";
var object = {
name : "My Object",
getNameFunc : function(){
return (function(){
return this.name;
}).call(this);
}
};
console.log(object.getNameFunc());
console.log( object.getNameFunc().call(object) );
16. Solution 2
var name = "The Window";
var object = {
name : "My Object",
getNameFunc : function(){
var that = this;
return function(){
return that.name;
};
}
};
console.log(object.getNameFunc()());
22. Double Confirm
var name = "The Window";
var object = {
name : "My Object",
getNameFunc : function(){
var name= “Inner name”;
return function(){
return name;
};
}
};
console.log(object.getNameFunc()());