문제

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