zaphod1984
zaphod1984

Reputation: 856

square bracket notation (not referring to object access!)

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

Answers (4)

helpermethod
helpermethod

Reputation: 62155

The expression [async.forEachSeries] puts the property forEachSeries into an array, then joins this array with the args array.

Upvotes: 1

Elian Ebbing
Elian Ebbing

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

cha0site
cha0site

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

karim79
karim79

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

Related Questions