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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With