From: Asen Bozhilov on 12 Apr 2010 17:09 Garrett Smith wrote: > That's useful, but not really directly related to "Square Bracket > Notation". It seems out of place for that article. Yes, that is not related with property access notations, but can it in addition. And general idea is to show distinctions between property names in square bracket notation, dot notation and property names in object literals. In object literal cannot be used result of expression for property name. That is the main difference with square bracket notation, where result of any valid expression by ECMA-262 can be used as property name. The difference with dot notation where property name is an Identifier, in object literal as property name can be used NumericLiteral and StringLiteral. So any valid Indentifier, NumericLiteral and StringLiteral can be used as property name. For example, the follow property names are syntactical valid by rules in ECMA-262-3 11.1.5 Object Initialiser: var obj = { propertyName : true, 2 : true, 'function' : true }; And the follow are not, because are not valid Identifier, StringLiteral or NumericLiteral: var obj1 = { function : false, 2 + 2 : false, 'str\' : false }; Another purposes to I suggested update of article is because ES5 does changes in dot notation and object literal for PropertyName. There is used IdentifierName instead of Identifier, which mean ReservedWords in ECMA-262-5 can be used as property name in dot notation. | ECMA-262-5 11.2.1 Property Accessors | Properties are accessed by name, using either the dot notation: | MemberExpression . IdentifierName | CallExpression . IdentifierName And in ES5 implementation the follow property access expressions are syntactical valid: myObj.function; myObj.super; And follows are invalid: myObj.0; myObj.\u0030; You can see some new things in ES5 by kangax slides. <URL: http://www.slideshare.net/kangax/say-hello-to-ecmascript-5 /> For my words see slide 46.
First
|
Prev
|
Pages: 1 2 3 Prev: FAQ Topic - How do I trim whitespace? (2010-04-07) Next: Problems with dynamic link creation |