Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which is preferable, a = [] or a = new Array()?

In Actionscript 3, which is preferable?

a = [1,2,3];

or

a = new Array(1,2,3);

It appears that calling the Array constructor with data as individual arguments would be slower and that the other method would be some sort of direct memory copy.

Do you know which is better to use in most cases, and why?

like image 437
Robin Rodricks Avatar asked Jan 07 '11 23:01

Robin Rodricks


1 Answers

I prefer the square brackets because it's a more concise and easy-to-read syntax.

The latter syntax will in fact be a bit slower, since you may replace the default array constructor by doing Array = function() { ... }; -- at least in most ECMAScript variants this works. So using that form will require the global Array function be looked up first.

like image 86
cdhowie Avatar answered Nov 15 '22 08:11

cdhowie