Skip to content
This repository was archived by the owner on Jan 25, 2022. It is now read-only.
This repository was archived by the owner on Jan 25, 2022. It is now read-only.

Could we have avoided "fields"? #274

@rdking

Description

@rdking

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.

  1. Is the prototype foot-gun the primary reason for avoiding the prototype?
  2. 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.

  1. Use a keyword to specify delayed initialization:
class Ex {
   inst object = {};
}
  1. Use an operator to specify that the initializer is an initialization function:
class Ex {
   object => {};
}
  1. Use a helper pseudo-function to wrap the initializer in an initialization function:
class Ex {
  object = class.inst({});
}
  1. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions