For your last MyClass
example, you could do this:
var myThis=this;
this.elements.each(function() { myThis.doSomething.apply(myThis, arguments); });
In the function that is passed to each
, this
refers to a jQuery object, as you already know. If inside that function you get the doSomething
function from myThis
, and then call the apply method on that function with the arguments array (see the apply function and the arguments variable), then this
will be set to myThis
in doSomething
.