Forum Moderators: open
I Have created an function which callsback to an other function that is variable.
Currently i use eval() to check if it is an function or not.
But i wonder if there is a way to do this without the use of eval.
Example:
myFunction('myCallback', 'Nothing');function myFunction($callback, $others) {
var $myFunctionHandler;
try {
$myFunctionHandler = eval($callback);
} catch ($expt) {
alert('callback is not a function');
return;
}
//Much other code etc.. etc..
$myFunctionHandler('Arg1', 'Arg2');
}
function myCallback($Arg1, $Arg2) {
alert($Arg1 +' - '+ $Arg2);
}
function myFunction($callback, $others) {
if( typeof $callback!= "function" )
{
alert('callback is not a function');
return;
}
}
function myCallback($Arg1, $Arg2) {
alert($Arg1 +' - '+ $Arg2);
}
// Don't wrap the first argument with quotes
myFunction(myCallback, 'Nothing');
That is, don't pass a string... pass the actual function reference.
[edited by: Fotiman at 5:37 pm (utc) on Nov. 29, 2006]