I have the following jQuery function (simplified):
function doSomething(el, str) {
el.find('.class').text(str));
}
Don't worry about the .text()
part, in reality I'm doing something a bit more complicated than that... But since that's irrelevant to my question, I'm just using .text()
here as a simple example.
The problem is, everytime I'm calling the doSomething()
function, the code looks like this:
doSomething($(this), foo); // the second argument is irrelevant
doSomething($(this), bar); // the second argument is irrelevant
As you can see, I'm always passing $(this)
as the first argument. Somehow I feel this is not the way to go... Can this function be improved so it automatically inherits the $(this)
from the context where it's called? Maybe something like the following:
$(this).doSomething(foo); // the foo argument is irrelevant
$(this).doSomething(bar); // the bar argument is irrelevant