proposal-destructuring-private
proposal-destructuring-private copied to clipboard
Alternate shorthand syntax
I get why the Ergonomic Brand Checks proposal prevents using #x
as shorthand for this.#x
, but did anyone discuss about using something like ##x
?
It’s a bit less nice to write, but if you’re typing one #
anyway it’s easy to type two of them, and it’s still shorter than this.#
. It’s also distinct enough to make it obvious that something special is happening with scoping.
A shorthand of any kind would not gain consensus; the receiver isn’t special - any object may have a private field on it, not just this
.
the receiver isn’t special
Yes, but I would bet that at least 90% of accesses of a private field are done via this
. Most of why you want a private field is to hide it from other code. Cases where you need to access it in other instances of your own class are just a subset of those, and I’d bet a small subset.
(That said, I don’t think I’m arguing with you. If you say that consensus would not be gained, you may well be right. I just don’t see why the reason you cited would prevent consensus on the suggestion, nor why a shorthand of any kind would fail—since lots of languages have this kind of shorthand—but that’s probably between me and the consensus, not your fault...)