Use .apply
func.apply(null, args)
If you need to bind to a specific area, you can pass another argument for use in this inside the function:
func.apply(scope, args);
In addition, the nuance of JavaScript is that you can call functions with undefined values. Thus, a small tweak to your existing code will work in 95% of all cases (this is not suggested as a solution, just pointing it out):
If your func is defined as:
function foo(a, b, c){ }
you get a , b , c , as well as several undefined values ββthat are ignored. As I said above, this works in 95% of cases. This does not work if you have ever checked arguments.length in the called function, since it will always be the same, regardless of the number of parameters that the function defines.
source share