hyperpolyglot
hyperpolyglot copied to clipboard
There is a way to pass array elements as separate arguments in Node.js
var a = [1, 2, 3];
add3.apply(window, a);
I don't think node has a global window object. I get "ReferenceError: window is not defined" when I try it.
@clarkgrubb
global
works also.
Also try using this
instead.
var a = [1, 2, 3];
add3.apply(this, a);
If you are nesting the functions you could set window=this
or global=this
at the beginning of the file
As this function doesn't need a context call, you can just:
add3.apply(null, a)