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

An alternative proposal and simple implementation #154

Closed
aimingoo opened this issue Oct 19, 2018 · 6 comments
Closed

An alternative proposal and simple implementation #154

aimingoo opened this issue Oct 19, 2018 · 6 comments

Comments

@aimingoo
Copy link

The project at aimingoo/private-property.

The goal of this proposal is to replace the highly controversial old proposal "proposal-class-fields". The new proposal with a concise implementation and aims to propose and accomplish One objective: SIMPLE!

^^~

Thanks for all.

A showcase, I really hope you can run it in person.

class ClassEx {
  private data: 200,

  private foo() {
    console.log("in instances,", '#data is ' + #data);
  }

  test(x) {
    console.log(#data);
    x#data = 'Hello World!';
    x#foo();
  }
}

// testcases
var obj = new ClassEx;
var more = new ClassEx;
obj.test(more);
@ljharb
Copy link
Member

ljharb commented Oct 19, 2018

The colon there is a forbidden extension, which is reserved for possible future type annotations, and would conflict with TypeScript and Flow.

Additionally, the asymmetry of using private for declaration and # for access wouldn't be acceptable to some on the committee.

Additionally, the shorthand #data was rejected for now, so all private access would need an explicit receiver for the time being.

@aimingoo
Copy link
Author

aimingoo commented Oct 19, 2018

@lijarb Thanks.

This is not just a proposal about syntax, its core claim is No Fields, and delivery an implementation based on the core concept of object is a collection of properties. This more succinct than the operational lexical context, And provides the possibility for implementations such as protectd property.

For grammar, I think that if can't deny the existing property declaration syntax, we can't deny the rationality of private property using : because the latter is a property. However, I can accept the suggestion to cancel the # shorthand, which looks good.

@ljharb
Copy link
Member

ljharb commented Oct 19, 2018

whether you use : or =, it’s either per-instance (fields), or its on the prototype (massive footgun).

@aimingoo aimingoo changed the title a alternative proposal and simple implementation An alternative proposal and simple implementation Oct 19, 2018
@yw662
Copy link

yw662 commented Oct 19, 2018

even more ugly than original, and does not fix '#'.

#149 is much more better than yours.

@aimingoo
Copy link
Author

@yw662

No. cannot implement protected property base on #149 , and it explicitly uses symbols and lexical contexts. BUT, class declaration itself has no lexical environment, so the solution must also create and maintain such an environment.

The good side is No fields. ^^.

@littledan
Copy link
Member

See the FAQ for an explanation of why we use # in this proposal rather than private.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants