> Dot access has always been nothing more than sugar -- a strict subset of the > domain of legal property names. This subset excludes private names just as it > excludes a whole range of strings, and for the same reason (insufficient > syntax support). Arguing for syntax support is one thing -- and I'm not > trying to claim that there is no room for it -- but this is a flawed premise.
Very few languages have the ability to directly create objects with methods "ex nihilo". In most mainstream languages, you need a class to do so. In that role, objects map names to values. If you use them in that role then compilers can statically analyze. That names are strings is an implementation detail. [] access is a very powerful feature and exploits that implementation detail. Object literals look very similar to dictionary/map literals which is why it is so easy to conflate objects and maps. But if you come from a static language such as Java, you tend to be more aware of the difference. - Pro: This conflation makes JavaScript very flexible. - Cons: We only get poor man’s maps via objects. Most other dynamic languages (Python, Ruby, Groovy) allow any value as a key. - Cons: Name collisions between map entries and properties is a constant source of trouble. For example, I suspect that the enumerable attribute of properties would not be needed if we didn’t have this conflation. - Cons: The more one uses [], the less a compiler can statically analyze/optimize. If we ever have maps with non-string keys then accessing elements should probably be done via a method. var map = new Map(); map.put(true, "Yes"); map.put(false, "No"); console.log(map.get(true)); I wouldn’t mind that (but I’ve coded a lot of Java, so that is to be expected). You can get map pseudo-literals by chaining put() method calls. -- Dr. Axel Rauschmayer a...@rauschma.de twitter.com/rauschma home: rauschma.de blog: 2ality.com _______________________________________________ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss