-
Notifications
You must be signed in to change notification settings - Fork 110
Could we have avoided "fields"? #274
Description
I wish Stage 3 was still a time when TC39 is open making major changes to a proposal. However, since it isn't, I can only ask these questions in hindsight.
- Is the prototype foot-gun the primary reason for avoiding the prototype?
- If so, was any consideration given to a syntax for avoiding the issue directly?
Here's what I'm thinking: suppose the syntax being used for public fields was instead used for prototype properties. I can think of several different approaches that solve the problem directly.
- Use a keyword to specify delayed initialization:
class Ex {
inst object = {};
}- Use an operator to specify that the initializer is an initialization function:
class Ex {
object => {};
}- Use a helper pseudo-function to wrap the initializer in an initialization function:
class Ex {
object = class.inst({});
}- Use a decorator to manage the initialization:
class Ex {
@inst object = {};
}All in all, any of these would successfully avoid the foot-gun without incurring any of the issues that will exist as a result of the current proposal. All 4 are relatively simple to implement. The only negative result of such a shift would be that private fields would need to be reworked. However, even that has a few solutions. But right now, what I'm looking for is an evaluation of whether or not this kind of idea presents a viable solution to the foot-gun, and if such a solution would have been enough to warrant dropping the "fields" concept (barring the issue of private) should it have been presented before Stage 3.