When in开发者_StackOverflow中文版itialising Arrays and Objects in JavaScript, is there any difference between these two statements:
var a = [];
var a = new Array();
or between these two statements:
var b = {};
var b = new Object();
If there is a difference, which is to be preferred?
there aren't any significant differences. You could use both, but if you use javascript for web client side scripting, it's better to use the shorter syntax, because the shorter the javascript code, the faster it will get downloaded and executed.
Brackets. Point.
They are shorter, they don't have hidden issues, and they are easier to pre-fill ( var a = [1,2,3,{"use":"brackets"},"because they are cool!"];
).
精彩评论