New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support optional private prop? #148
Comments
How did you access a private prop from outside of class definition of
|
class A{
#x = {a: 1}
a(){
return this?.#x.a
}
}
new A().a() |
class A{
#x = {a: 1}
a(){
const obj = this
return obj?.#x.a
}
}
new A().a() |
Not outside, inside. |
It probably makes sense for
One possible usage might be class A {
#x; // undefined
a() {
return this.#x?.a;
}
} And yes, this code is fine in meriyah. My argument is because private prop is statically checked, it doesn't make any sense to have |
Just follow what the proposal says |
You point make sense, I wounder why Private Fields in class A{
#x = {a: 1}
}
class B extends A{
a(){
return this?.#x.a
}
}
new B().a()
Uncaught SyntaxError: Private field '#x' must be declared in an enclosing class |
This? class A {
#a=1
a() {return this?.#a}
}
A.prototype.a.call(undefined)
A.prototype.a.call(new A) |
Private class fields and methods Issue #28: Should optional chains support the upcoming private class fields and private methods, as in a?.#b, a?.#b() or a?.b.#c? Quoting microsoft/TypeScript#30167 (comment): This one isn't baked into the proposal yet, simply because private fields themselves aren't baked yet. So we don't want to hold up this proposal if that one happens to stall out. Once that one has reached Stage 4, we will address it then. tc39/proposal-optional-chaining#28 |
In short, there were lots of arguments like ours. But it's in the proposal now. |
The text was updated successfully, but these errors were encountered: