Frage

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);
War es hilfreich?

Lösung

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);
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top