If you use your own .forEach instead of $.each , you can set this to the callback by sending the second argument ...
array.forEach(function(e, i) { alert(this.name); }, this);
You will need to fix older browsers, including IE8 ...
Or you can use jQuery $.proxy to return a function with the desired value of this ...
$.each(array, $.proxy(function(i, e) { alert(this.name); }, this) );
user1106925
source share