I have a question concerning how the this pointer is treated in a nested function scenario.
Say I insert this following sample code into a web page. I get an error when I call the nested function doSomeEffects(). I checked in Firebug and it indicates that when I am in that nested function, the this pointer is actually pointing to the global window object - which I did not expect. I must not be understanding something correctly because I thought since I declared the nested function within a function of the object, it should have local scope in relation to the function (i.e. the this pointer would be referring to the object itself like how it is in my first if statement).
Any pointers (no pun intended) would be appreciated.
var std_obj = {
options : { rows: 0, cols: 0 },
activeEffect : none,
displayMe : function() {
// the 'this' pointer is referring to the std_obj
if (this.activeEffect==fade) { }
var doSomeEffects = function() {
// the 'this' pointer is referring to the window obj, why?
if (this.activeEffect==fade) { }
}
doSomeEffects();
}
};
std_obj.displayMe();