Approach of new Object methods in ES5

Brendan Eich brendan at mozilla.com
Fri Apr 16 09:58:17 PDT 2010


On Apr 16, 2010, at 12:51 PM, Erik Arvidsson wrote:

> On Fri, Apr 16, 2010 at 08:43, Brendan Eich <brendan at mozilla.com>  
> wrote:
>
> ES4 since Waldemar's 1998-era JS2 work was concerned with the  
> problem of versioning APIs implied by (1) greatly, and not just  
> adding properties: deleting and redefining too. ES4 proposed  
> namespaces (like Common Lisp packages, IIRC) as the solution. But  
> namespaces are out for Harmony.
>
> My hope is that we can avoid versioning the object model and instead  
> simply extend certain objects that we effectively "reserve to the  
> implementation" (as ANSI and then ISO C does with certain global  
> names, e.g. __foo and _BAR). Indeed Ajax library developers now  
> generally avoid extending standard prototypes, and it's plausible  
> this best-practice could be extended to the built-in constructor  
> objects too.
>
> These are considered best practices because it breaks in the  
> presence of other code outside your control. There is a reason why  
> Prototype.js is popular. It allows people to write code in a more  
> sane way, using methods that are bound to objects instead of global  
> functions. If we had something like ES4 namespaces without all the  
> issues (one can always dream) I'm sure that this best practice would  
> be reversed.

You're right -- I hear this from lots of developers. Ben Galbraith,  
for example, says Prototype reduces keystrokes and he's right,  
keystrokes aggregated over a long time do count. There is a  
corresponding readability issue.

I was describing things as they are, not as they might be. But we do  
not have a namespace solution.

However, ES5 *does* allow libraries to bind non-enumerable properties  
of prototype objects. This is half of the solution, and if the  
prototype in question is Object.prototype, or perhaps even then if the  
name is obscure enough, a library might risk breaking object detection  
on that name in the global object.

Another Harmony idea: http://wiki.ecmascript.org/doku.php?id=strawman:names 
  for unforgeable property names not equated to any string. These  
cannot collide, and with sugar to let them be used with . (not only in  
computed property accesses using []), we may have a complete solution  
for injecting new "names" into standard prototypes without breaking  
existing code.

/be

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


More information about the es-discuss mailing list