New private names proposal

David Flanagan david at
Wed Dec 22 00:38:34 PST 2010

On 12/21/2010 11:58 PM, Brendan Eich wrote:

> I'm not keen on adding # as a sigil for private names, but this is mostly because such things are ugly, Perlish line noise. Under the "explicit is better than implicit" philosophy, and in particular the desire to eliminate even a static (compile-time only) parallel namespace, *maybe*.

Ruby uses @, and while that still looks like Perl line noise, it doesn't 
in practice seem to get in the way all that much: there just aren't that 
many of them in most Ruby code, in my experience.  (Part of that is 
because of Ruby's metaprogramming methods attr_reader and attr_accessor 
that define @ fields and corresponding getter and setter methods.)

And speaking of Ruby and attr_reader, could the need for new syntax be 
reduced or eliminated with a sufficiently clever metaprogramming API? 
For example, and using an ungainly ES5-style function name:

   // Create and return a private name, and define a getter "foo" for it
   var name = Object.definePrivateProperty(o, "foo");                 // => anyone can query the private property
   o[name] = new_value;  // Setting the property requires the name object

(I don't know how this would handle private fields in object literals, 


More information about the es-discuss mailing list