Specs: ECMAScript 5 and ECMAScript 3(规格: ECMAScript 5和ECMAScript 3)
Section 11.1.5 in the ECMAScript 5 specification:(ECMAScript 5规范中的11.1.5节 :)
ObjectLiteral :
{ }
{ PropertyNameAndValueList }
{ PropertyNameAndValueList , }
So yes, it is part of the specification.(是的,它是规范的一部分。)
Update: Apparently this is new in ES5.(更新:显然,这是ES5中的新功能。)
In ES3 (page 41), the definition was just:(在ES3(第41页)中,定义仅为:)
ObjectLiteral :
{ }
{ PropertyNameAndValueList }
For arrays literals ( Section 11.1.4 ) it is even more interesting ( Update: this already existed in ES3):(对于数组文字( 第11.1.4节 ),它甚至更有趣( 更新: ES3中已经存在):)
ArrayLiteral :
[ Elisionopt ]
[ ElementList ]
[ ElementList , Elision_opt ]
(where Elision_opt
is Elision opt , meaning the Elision is optional)((其中Elision_opt
是Elision opt ,这意味着Elision是可选的))
Elision
is defined as(Elision
定义为)
Elision :
,
Elision ,
So, an array literal like(因此,像这样的数组文字)
var arr = [1,2,,,,];
is perfectly legal.(是完全合法的。)
This creates an array with two elements but sets the array length to 2 + 3 = 5
.(这将创建一个包含两个元素的数组,但是将数组长度设置为2 + 3 = 5
。)
Don't expect too much from IE (before IE9)...(不要对IE期望太多(在IE9之前)...)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…