I have a function that accepts an anonymous function as an argument and sets it to a variable (scoped) for reference. I then try to execute another function with that reference but it obviously fails since that function is out of scope.
I was wondering if anyone knew of a simple way of passing the anonymous function straight through as an anonymous function, avoiding the scoping issue?
EDIT: To clarify, the el element is defined after the function is isolated from the arguments list. Additionally, the el element is a part of the arguments list as well. Were this code to be used by only me, I would likely have used a two argument list with the second argument being an array or hash object but unfortunately this code is going to be used by some folks who are less familiar with JS or even coding for that matter.
Thanks for the help!
Here is the relevant portion of my code:
locate : function(){
if ((!arguments)||(!arguments.length)) return;
arguments = [].splice.call(arguments,0); //This just converts arguments into an array
for (var i=0;i<arguments.length;i++){
if (typeof(arguments[i])=='function'){
var tf = arguments.splice(i,1);
break;
};
};
if (!tf) return;
JAS.Globals.eventListen('click',el,tf);
}
This is abbreviated so just trust that el is defined. JAS.Globals.eventListen is just an intelligent addEventListener.