开发者

Initialising Arrays and Objects: using brackets or 'new'?

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!"]; ).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜