As the title, is there a way to pass an element into a function without using an anonymous function?
Or in other words:
I know I can pass element into function as follows:
function fakeFunction(elementReceived){
elementReceived.hide();
}
$(".class-x").each(function(){
fakeFunction($(this));
});
which is not acceptable as I am required to prevent using anonymous function due to some problem in testing.
So I write something like this:
function fakeFunction(){
$(this).hide();
}
$(".class-x").each(fakeFunction);
This is better but the readability is decreased, as the function in the actual code is very far away from the calling line and using $(this) directly is confusing.
I was told (and was requested to investigate) that something like the following should be possible:
function fakeFunction(elementReceived){
elementReceived.hide();
}
$(".class-x").each(fakeFunction, $(this));
but the $(this) in the above code passed the whole document instead..... What should be the proper way to write it?