Reputation: 856
i was digging throug some code (async module for nodejs) and ran into the following notation:
return fn.apply(null, [async.forEachSeries].concat(args));
if seen this notation using the square brackets alot, but have no idea whoat it means exactly. is this related to ES5?
greetings!
Upvotes: 1
Views: 394
Reputation: 62155
The expression [async.forEachSeries]
puts the property forEachSeries
into an array, then joins this array with the args
array.
Upvotes: 1
Reputation: 19027
It's a notation for array literals. The following code will create an array with 4 elements:
var x = [1, 4, 9, 16];
An array is itself an object and has methods like concat to join two arrays and create a new array.
Upvotes: 0
Reputation: 10717
It's a list. You can do:
[1,2,3,4,5]
To get a list in JavaScript, and concat
is a list method.
Upvotes: 0
Reputation: 342635
It's really quite simple. You are basically gluing two arrays together and passing the resulting array as second argument to apply. See:
https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/concat
e.g.:
// this should clarify
console.log([1, 2, 3].concat([4, 5]));
Upvotes: 2