Following is my code -
(function($){
obj = {
alertText: function(){
console.log('Called');
},
testFunc: function(){
console.log(this);
this.alertText();
},
checkFunc: function(){
inner();
function inner(){
console.log(this);
this.alertText();
}
}
}})(jQuery)
When I call testFunc(), alertText() is properly called over the this keyword.
However the call to alertText() using this fails inside inner() (TypeError saying this.alertText is not a function) after I call the checkFunc() function.
When I console this as shown above, I get different contents inside it - the one inside testFunc() show the object obj, while the one inside inner() shows the Window object.
Why is this so? Why does this mean differently at two places?