callback - javascript send arguments object as argument -


I have to debate the callback function as a real argument. How do I do that? Callback requires a variable number of arguments.

Example function such as:

  var func = function (callback) {doSomething (function () {// target is the actual logic callback (argument)}) In the callback function, pass the object to the arguments; }   

Thanks in advance.

This can be a similar question like this:

But I do not have to answer that question nor the answer.

EDIT: If possible, I do not want to pollute the world.

Use to apply a callback so that the array items are in the form of personal arguments on the function.

  callback.apply (this, logic);   

apply takes references, and logic as an array, and passed each item of the array as a designated argument of the function implemented can go. / P>

  function two (first, second) {alert (first), alert (second); } Two.apply (tap, ["hello", "world"]); // Alert "Hello", then "World"   

The implementation of ES3 requires that apply the second argument is an array or argument object. ES5 makes it more generous in it until it looks like an array - there is length in the property, and related integer indexes, it will work.

Comments