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.

Private fields are tied to classes #93

Description

@futpib

Since class is syntactic sugar for function and "special" "prototype" property (at least class constructors are defined in terms of function and "prototype"), I feel like it's better to tie private fields to those constructs. In other words, one should be able to achieve exactly same results with function and prototype as with a class.

Currently this proposal adds PrivateFieldEnvironment to Execution Contexts and the only defined way to create new PrivateFieldEnvironment is ClassDefinitionEvaluation (that is evaluation of a class ... expression).

This will result in that whenever user wants to create on object with truly private fields, they will have to use a dummy class declaration with all it's limitation (like inability to declare arbitrary class members in runtime in reflective manner (without eval-like features)).

I propose that at least

  • a way of creating a new PrivateFieldEnvironment and a way of defining new PrivateFieldIdentifers in that environment in reflective manner are defined
  • ObjectDefineProperties (with ToPropertyDescriptor) are altered to allow definition of an object with private fields using Object.create

EDIT: The Object.create part has been revised as unnecessary later in this thread.

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