You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jan 25, 2022. It is now read-only.
I have another proposal that is opposed to my previous proposal #75. This proposal goes in the opposite direction to the other paradigm of having record-like syntax.
Normally with block scoping we can do something like this:
constx='x';{constx='different x';consty='y';console.log(x);// outputs 'different x'console.log(y);// outputs 'y'}console.log(x);// outputs 'x'console.log(y);// Uncaught ReferenceError: y is not defined
This makes sense and we all understand it.
Class declaration is not quite like block scoping in that we don't use const or let but if we were to add an internal block scope like syntax to classes we could treat the internal properties as private instance properties. For example:
To describe how this would work we would say this block scope is created for each instance and can be referenced from all class methods. The block scope syntax would mirror the class declaration syntax and internally you would treat all properties within the block scope as you treat regular class properties with respect to initiliazers. Block scoped methods would be bound to the class instance but getters/setters wouldn't make any sense in this case so they can be prohibited.
This and #75 are two very different proposals but each try to align this proposal with the way developers understand JS to work today. This proposal doesn't offer a way to iterate or access private properties via a variable but it does remove the need for destructuring all together (which would be my biggest complaint about the current proposal).
The text was updated successfully, but these errors were encountered:
One of the biggest issues with basing privacy on lexical scope is that it is unclear how we would support accessing private fields from other instances of the same class. Do you have an idea for how to provide this capability?
I have another proposal that is opposed to my previous proposal #75. This proposal goes in the opposite direction to the other paradigm of having record-like syntax.
Normally with block scoping we can do something like this:
This makes sense and we all understand it.
Class declaration is not quite like block scoping in that we don't use const or let but if we were to add an internal block scope like syntax to classes we could treat the internal properties as private instance properties. For example:
To describe how this would work we would say this block scope is created for each instance and can be referenced from all class methods. The block scope syntax would mirror the class declaration syntax and internally you would treat all properties within the block scope as you treat regular class properties with respect to initiliazers. Block scoped methods would be bound to the class instance but getters/setters wouldn't make any sense in this case so they can be prohibited.
This and #75 are two very different proposals but each try to align this proposal with the way developers understand JS to work today. This proposal doesn't offer a way to iterate or access private properties via a variable but it does remove the need for destructuring all together (which would be my biggest complaint about the current proposal).
The text was updated successfully, but these errors were encountered: