this never implied in JavaScript (as in Java). This means that if you do not call the function as a method for the object, this will not be bound to something reasonable (it will be bound to the window object in the browser). If you want to have this inside a function, this function should be used as a method, that is:
var teste = {name:'marcos'}; $(teste).each(function(){ this.sayName = function(){ alert(this.name); } this.sayName(); });
Then sayName is a method and is called in this
Mathias schwarz
source share