Вопрос

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);
Это было полезно?

Решение

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);
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top