-
Notifications
You must be signed in to change notification settings - Fork 113
and yet another suggestion for "private but not closure" #153
Comments
That would conflict with a public "private" property, which works just fine in existing JS. |
@ljharb |
Absolutely they would. Any existing possible public property can't be repurposed. |
However, |
It's a reserved keyword - not a reserved property name. Anyone can do it, and "should" is irrelevant. |
Agree with @ljharb: there is likely to be significant web compatibility impact if we choose a name like this that's legal, and for many years, even keywords have been permitted as property names. |
@yw662 "private but not closure" implementation in #154 , source code released at example.js in aimingoo/private-property. |
object.private might shadow legal property names, but it shadow only 1 property name. However, If you really worry about this, we can do object[Symbol.private]. |
No, because you can't use var obj = {
"#foo": 2
};
obj.#foo; // This code is currently not valid! You will always need to `obj["#foo"], which never access private properties |
not a problem. |
Also, your proposal isn't much more ergonomic that the current way of having private properties, while the current proposal is: // ES6
var x = new WeakMap;
class Foo {
constructor() {
x.set(this, 0);
}
setX() {
x.set(this, 1);
}
}
// Your proposal
class Foo {
[Symbol.private] = {
x: 0,
};
setX() {
this[Symbol.private].x = 1;
}
}
// Current proposal
class Foo {
#x = 0;
setX() {
this.#x = 1;
}
} Also, what is |
should be |
I don't think that anyone would accept a private props implementation where
I don't think that this would work:
How would that work? |
I can't imagine how to think of using # as a private variable tag. |
No # Union, join us. |
It's really not clear how Symbol.private could provide the encapsulation goals in this proposal, so closing this issue. |
roughly just replace
#
with.private.
, which make much more sense.since you dont like it, just try
Symbol.private
example:
This will introduce a new well known Symbol
Symbol.private
, and the only thing the engine need to do is, makeobject[Symbol.private]
private.The text was updated successfully, but these errors were encountered: