shortcuts for defining block-local private names, plays nicely with @foo syntax

Herby Vojčík herby at mailbox.sk
Mon Jan 23 11:51:11 PST 2012



Brendan Eich-2 wrote:
> 
>> Herby Vojčík <mailto:herby at mailbox.sk>
>> January 23, 2012 3:21 AM
>> It can be solved this way:
>>
>>   module {
>>     private foo, bar;
>>
>>     export function factory1 (args) { ... }
>>
>>     export function factory2 (args) { ... }
>>
>> but then foo and bar are known to the rest of the module. It was not 
>> the premise.
> 
> There is nothing wrong with this solution, and everything right. If you 
> want to keep foo and bar secret from other modules, you've done so. If 
> you, for some reason, want to keep them secret from other contents of 
> this module, use a block (but you'll have a harder time exporting -- 
> export must come at module top level).
> 

In other way, it is impossible to have truly lexical-local private names.
You must define them all at the upper level, tens or maybe hundreds of lines
back. And lexical-private local names will, imo, be the most frequent
scenario where private names will be used. That is the most natural use for
them: as a private keys in a "class" of objects - class now in a most broad
meaning - there @foo must always be the same @foo.


Brendan Eich-2 wrote:
> 
> In any case, we're not making lexical singletons of private 
> declarations, or of any declarations, however nested. That's simply a 
> pigeon-hole problem for programmers who need the usual generativity JS 
> declared forms (closures notably) provide.
> 

Could you explain, please?


Brendan Eich-2 wrote:
> 
> One bad precedent like this 
> we fixed: ES3 regexp literals, which were singular per source literal.
> 

Private names are deeply frozen. That is, immutable. No regexp-related
problems should appear here.

Why are you so much again lexical singletons? In this case, they are
harmless and very useful. Much more useful than is the shortcut for const
Name.create().


Brendan Eich-2 wrote:
> 
> /be
> 

Herby
-- 
View this message in context: http://old.nabble.com/shortcuts-for-defining-block-local-private-names%2C-plays-nicely-with-%40foo-syntax-tp33180896p33190604.html
Sent from the Mozilla - ECMAScript 4 discussion mailing list archive at Nabble.com.



More information about the es-discuss mailing list