Lexically Scoped Object Extensions (was About private names)

François REMY fremycompany_pub at yahoo.fr
Mon Mar 21 23:50:04 PDT 2011

From: Brendan Eich
Sent: 21 March 2011
> On Mar 21, 2011, at 1:13 PM, Erik Arvidsson wrote:
> >
> > The above use case cannot be solved using private names because
> > private names conflict with public names.
> I don't see this, though. Don't oversell!

I think it's true: you can't do this with private name.

private filter;
Object.filter = function defaultFilter() { ... };
[0, 1, 2].filter(...) // will triggers Object.filter and not Array.filter, 
because filter is not "filter" anymore but a private name instead.

If you use a "normal name" with a reduced visibility instead, the classical 
prototype chain will continue to works as expected.


More information about the es-discuss mailing list