Jquery $().each method obscures 'this' keyword
- by Jeff Fritz
I am creating a Javascript object that contains a function that executes a jQuery each method like the following:
function MyClass {
Method1 = function(obj) {
// Does something here
}
Method2 = function() {
$(".SomeClass").each(function() {
// 1 2
this.Method1(this);
});
}
}
Which object is each THIS referring to? jQuery is referring to the item returned from the each iteration. However, I would like This[1] to refer to the containing class...
How can I refer to the containing class from within the jQuery loop?