names [Was: Approach of new Object methods in ES5]

Peter van der Zee ecma at qfox.nl
Fri Apr 16 13:37:50 PDT 2010


On Fri, Apr 16, 2010 at 9:48 PM, P T Withington <ptw at pobox.com> wrote:

> On 2010-04-16, at 14:31, David Herman wrote:
>
> > Tucker: if the "property-nameness" attribute weren't transferrable but
> names were objects with property tables, do you think that would be powerful
> enough? Or would you want the ability to define custom constructors, e.g.:
> >
> >    function MyCustomKindOfNamespace() {
> >        Object.becomePropertyName(this);
> >        // ...
> >    }
>
> I was thinking that for exploratory purposes, you might want a custom
> constructor so you could, say, enumerate all the names in your custom
> namespace, or test for a name being in your namespace.  But I could do that
> with just properties by (something like):
>
>  private customnames = [];
>  private custom;
>  function CustomName (pretty) {
>    let name = new Name;
>    name[custom] = pretty;
>    name.toString = function () { return "custom::" + this[custom]; }
>    customnames.push(name);
>    return name;
>  }
>
>  function isCustom(name) { return name.hasOwnProperty(custom); }
>
>  etc.
>
> A conundrum is that you don't want private names to be revealed by property
> enumeration in general, but IWBN if they could be enumerated by someone with
> access to the namespace.  Using the idea of names having properties
> themselves, if there were a way to say "enumerate the properties that have
> some property", you could use a private property as a capability to get at
> private names.  I'm sure we can have hours of fun suggesting how to extend
> the `for` syntax to handle that.  :)
>
>
> The straw seems awkward and unnecessarily complex compared to the
.toPropertyName suggestion. It could just return true or false to determine
whether the identity or .toString should be used as property reference.
Including the proposed hidden identity reference properties. I wouldn't
"sacrifice" private for this.

 - peter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20100416/76cb427f/attachment.html>


More information about the es-discuss mailing list