Lexically Scoped Object Extensions (was About private names)

François REMY fremycompany_pub at yahoo.fr
Tue Mar 22 00:29:38 PDT 2011

> Sure, but the problem (as people keep pointing out) has two solutions: 
> close the scope in which filfter binds to a private name, or use a 
> renaming private declaration.
> It's not perfect but there's no absolute inability to call public filter 
> and private filter.

Adding "filter" to the Object property was done to have a fallback when the 
object you work on don't have a "filter" method built-in. In case the object 
you're working on has a "filter" method, it should be used. In this case, if 
you use private name, you can't have this behavior right (ie: write 
"myObj.filter()" and use the filter method implemented in myObj, if any, or 
the temporary extension to Object.prototype). It's because your intent was 
not to create a private name. It was to define a temporary extension to an 

If you want this behavior right using private names, you'll need 
"if(myObj["filter"]) { myObj["filter"]() } else { myObj.filter(); }" or 
"(myObj["filter"]||myObj.filter).call(myObj)" which is really ugly. 

More information about the es-discuss mailing list