what doesn't workso ... let's say you have this block of code...
var myObj1 = { greeting: "Hi!", say: function() { function doStuff() { alert(this.greeting); }; doStuff(); } } alert(myObj1.say()); Solution 1 |
why does it work?THIS must reference to something only 1 level up.
|
var solution1 = {
greeting : "Good Morning", say: function() { function doStuff() { alert(this.greeting); }; doStuff.call(solution1); } } alert(solution1.say()) |
|