Lexically Scoped Object Extensions (was About private names)

Allen Wirfs-Brock allen at wirfs-brock.com
Tue Mar 22 08:27:14 PDT 2011


I think a more precise statement is you can't do this with private names alone.

As the classbox work explains, you also have to have a modified property lookup algorithm that takes into account that a [[Get]] may be satisfied based upon either the global or local key value associated with the name .  This was reflected in by counter example where I explicitly delegated to the public named property if it exists:

private filter;
 Object.prototype.filter = function(fun) {
    var publicFilter= this["filter"];
    if  (publicFilter) return publicFilter.apply(this,arguments);
   ...

In practice I don't think you would actually do it that way, but it does show that two distinct property key values are in play.

Allen




On Mar 21, 2011, at 11:50 PM, François REMY wrote:

> 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.
> 
> 
> Regards,
> François 
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss



More information about the es-discuss mailing list