Two kinds of [] (was: Re: shortcuts for defining block-local private names, plays nicely with @foo syntax)

Herby Vojčík herby at mailbox.sk
Mon Jan 23 12:20:51 PST 2012


Allen Wirfs-Brock wrote:
>
> Below...
> Brendan Eich <brendan at mozilla.org> wrote:
>  > Allen Wirfs-Brock <mailto:allen at wirfs-brock.com>
>  > January 23, 2012 8:43 AM
>  > On Jan 22, 2012, at 7:36 PM, Tab Atkins Jr. wrote:
>  >
> ?..
>  >
>  > const getIterator = Iterator.getIterator;
>  > myCoolObject.prototype. at getIterator = function() {...}
>
> Why wouldn't myCoolObject.prototype[iterator.getIterator] work?
>
> /be
>
> It would, for now. But, I think you gave the reason for avoiding this
> pattern in another reply. If we ever want to adopt my Reformed Object
> Model proposal then we should avoid using [ ] for private name property
> access. lt would actually still work fine for objects with default [ ]
> behavior but not for collection objects that redefine [ ] access.

Losing generic [] as a way to access all "native" properties of the 
object is big price. What about half-way: modify object reformation to 
have "native []" and "logical []" in parallel.

You can use
   x.foo
   x["foo"]
   x.["foo"]
syntaxes (and x. at priv, too), and if you define the latter as "native 
property access", for the time being equivalent to [], but later [] can 
be redefined (or vice versa, but it seems .[] is more akin to . and .@ 
and [] seems better for "logical" element access), you've got the 
collection [] but don't lose the object-structural [].

> Allen

Herby


More information about the es-discuss mailing list