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

P T Withington ptw at
Fri Apr 16 12:48:49 PDT 2010

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]; }
    return name;

  function isCustom(name) { return name.hasOwnProperty(custom); }


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.  :)


More information about the es-discuss mailing list