shortcut for private(this)

Erik Arvidsson erik.arvidsson at gmail.com
Fri Jan 20 10:59:50 PST 2012


On Fri, Jan 20, 2012 at 10:46, Herby Vojčík <herby at mailbox.sk> wrote:
> No, I asked for something else. How do it do: "get a private property of
> <<foo>> whose name is computed by <<expression>>"? Something like
> foo.@[expr]? Or is there no way to do it?
> In other words, what is [] syntax for foo. at bar? foo.@["bar"]? foo["@bar"]?

@bar is a shorthand[*] for this[bar]
object. at bar is a shorthand[*] for object[bar]

There is no way to compute a string "bar" to do the lookup since that
would break private name encapsulation:

let object = ...
{
  let key = Name.create()
  let secret = {}
  object. at key = secret
}

There must be no way to get access to secret here.

[*] Using @ does not really invoke []. That is important if private
names are going to work with the extended collection proposals Allen
proposed. http://wiki.ecmascript.org/doku.php?id=strawman:object_model_reformation

-- 
erik


More information about the es-discuss mailing list