clarkgrubb / hyperpolyglot

hyperpolyglot.org
Other
473 stars 94 forks source link

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

Open Finesse opened 8 years ago

Finesse commented 8 years ago
var a = [1, 2, 3];
add3.apply(window, a);
clarkgrubb commented 8 years ago

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

7fe commented 8 years ago

@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 commented 8 years ago

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

add3.apply(null, a)