> In order for this to work you have to abandon the idea of scoped private
> identifiers. I say: make all private identifiers scoped to the compilation
> unit.
This is the part of your suggestion that I don't like: it makes private
identifiers too blunt a tool. You end up sharing with more code than you want,
and when you refactor by pulling code out of one compilation unit and into
another, you share less than you want. Lexical scope is a tried-and-true
mechanism for controlling sharing, and it works better than compilation units.
Moreover, we don't even have a clear notion of compilation unit in the language.
But your idea suggests yet another alternative worth adding to our growing
pantheon. We could allow for the scoping of private names, but always require
them to be prefixed by the sigil. This way there's no possibility of mixing up
public and private names. So to use an earlier example from this thread
(originally suggested to me by Allen):
function Point(x, y) {
private #x, #y;
this.#x = x;
this.#y = y;
}
For your counter example, the original names proposal allowed for object
literals to declare private properties, and the private name was scoped to the
entire literal. So you'd write:
var counter = {
private #count: 0;
next: function() { return this.#count++; }
reset: function() { this.#count = 0; }
};
This is of course still strictly noisier than the original private names
proposal, but it does have the advantage of never capturing public names by
private declarations. It doesn't, however, address your concern about
generativity. Personally, I like the generativity; I think it matches up with
the use cases. But I acknowledge that it might be subtle.
Dave
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss