Pergunta

Well, again. I want to call a function inside a recursive function with all the arguments its meant to:

function foo(callback /* , callback args */) {
  var args;
  for(var i=1;i<arguments.length;i++) {
    args.push(arguments[i]);
  }
  // somehow set the timeout to foo
  callback.apply(args);
}

I already tried to apply to setTimeout too but doesnt seem to work:

args.unshift(foo, 100, callback);
setTimeout.apply(args);
Foi útil?

Solução

The array of arguments should be the second argument to apply.

You need to add an argument to determine the value of this before it.

setTimeout.apply(window, args);
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top