There is a way to pass array elements as separate arguments in Node.js #48

Open
FinesseRus opened this Issue Nov 28, 2015 · 3 comments

Projects

None yet

4 participants

@FinesseRus
var a = [1, 2, 3];
add3.apply(window, a);
@clarkgrubb
Owner

I don't think node has a global window object. I get "ReferenceError: window is not defined" when I try it.

@limeblack

@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

@hbarcelos

As this function doesn't need a context call, you can just:

add3.apply(null, a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment