I’ve just asked about calling functions by name, now I want to process return statement after SetTimeout:
function ECall(funcName, arg)
{
command += "(";
for (var i=1; i<arguments.length; i++)
{
command += "'" + arguments[i] + "'";
if (i != arguments.length-1) command += ',';
}
command += ")";
//var funcPtr = eval(funcName);
//return funcPtr(arg); // This works, but I need SetTimeout
setTimeout('window[\'' + funcName + '\']' + command, 1000);
}
setTimeout works great, but I have to save return value of called function. When I write: setTimeout('alert(window[\'' + funcName + '\']' + command + ')', 1000);
It alerts return value of function. How can I store it?
You don’t need to use any of this string manipulation. Just pass a function reference to
window.setTimeout(). To store the returned value of the function, simply assign it to a variable in the function you pass towindow.setTimeout()