2

For a normal ("Native") JavaScript objects, where the property name is a valid identifier, the expressions x.y and x["y"] are always semantically equivalent.

Is this equivalency guaranteed for Host Objects?

[..an] object supplied by the host environment to complete the execution environment of ECMAScript.

If not, are there notable exceptions? (In Cocoon, Crosswalk, IE, etc?)

In particular I am interested in the Window (window) and other DOM Objects; and if there are any known "exceptions" to the expected behavior, or if there are any environments in where such is possible.

user2864740
  • 60,010
  • 15
  • 145
  • 220
  • Using bracket notation is the same as dot notation, everywhere, as it's in the ECMA specs. – adeneo Nov 10 '14 at 00:02
  • Well `x.1` has different behavior than `x["1"]`, but that about syntax, not semantics. It would be no different for native / host objects. – p.s.w.g Nov 10 '14 at 00:07

1 Answers1

2

It should be identical. From Section 11.2.1 (Property Accessors) of the Ecma-262 Edition 5.1, we have:

Properties are accessed by name, using either the dot notation:

MemberExpression . IdentifierName 
CallExpression . IdentifierName

or the bracket notation:

MemberExpression [ Expression ]
CallExpression [ Expression ]

The dot notation is explained by the following syntactic conversion:

MemberExpression . IdentifierName

is identical in its behaviour to

MemberExpression [ <identifier-name-string> ]

and similarly

CallExpression . IdentifierName

is identical in its behaviour to

CallExpression [ <identifier-name-string> ]
Ben Reich
  • 16,222
  • 2
  • 38
  • 59