-
Notifications
You must be signed in to change notification settings - Fork 4
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
Add protected #x
#6
Comments
I firmly believe that "protected" has no place in JavaScript; primarily because there's no way to reliably "protect" anything. Access isn't a "level", it's a binary - either something is reachable, or it's not. If it's reachable, it's public, and if not, it's private. |
@ljharb, please re-read my post. Do you understand my idea and why I say that |
so you're suggesting to use |
I think he's suggesting I think that's a bit confusing. Why not just hoist the private declaration one scope higher? |
It's not always suitable, consider this: const mixinA = klass => {
protected #id;
return class A extends klass {
[#id] = 1;
}
}
const mixinB = klass => {
protected #id;
return class B extends klass {
[#id] = 1;
}
} Moving |
What about adding
protected #x
notation? It seems to be natural extensions to this proposal, since majority of developers will expect to havepublic
/private
/protected
keywords used in same fashion and might be surprised if something is missing (it also appliable to #5).protected
keyword might solvepositional vs closure
problem described in tc39/proposal-class-fields#60Let's make
protected
the same asprivate
whith one exception,private
belongs to closure scope, whileprotected
belongs to lexical scope. To illustrate:private
protected
protected
could be extremely useful for some types of mixins, while others are still possible.BTW, @ljhard, this type of
protected
actually does protect something 😉It works even better with #1. For example:
Addition
It might be extended a little bit in root-level lexical scope. Consider this:
Without any specific behavior
protected
atroot-level
lexical scope will behave exactly the same asprivate
, so previous code will be euqal to following:But to make it closer to meaning of
protected
from other languages, we may change this a little bit, so code will be equal to:P.S.
I'm not sure what term will be preferable for this proposal:
lexical scope
orouter closure scope
. They probably might have slight difference, but I don't see how it can affect this proposal.The text was updated successfully, but these errors were encountered: