-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal: abstract-refs based private
methods in class literal
#12
Comments
Hi @zloirock! Thanks for the feedback. Based on discussions here and at the Nov TC39 meeting we've moved away from the "abstract references" design. It has now been split up into a function bind operator proposal and a private fields proposal:
Please check those out and let me know what you think. |
@zenparsing wow... Method extraction syntax really lacked in abstract refs proposal. Not sure about those conception private fields - unusual. But i don't see anything about right-to-left syntax modifiable in userland. I hope that the move away of these parts of abstract-refs does not buries something like |
@zloirock Interesting. Would you mind talking about how you use |
@zenparsing basical, demo: let {map} = Dict;
// static version:
var O = map({q: 1, w: 2, e:3}, it => it * it);
log(O); // => {"q":1,"w":4,"e":9}
// method version, redefined @@referenceGet:
var O = ({q: 1, w: 2, e:3})::map(it => it * it);
log(O); // => {"q":1,"w":4,"e":9}
// virtual accessors:
let size = {
[Symbol.referenceGet](it){
return Object.keys(it).length;
},
[Symbol.referenceSet](it, length){
for(let key of Object.keys(it).slice(length))delete it[key];
}
}
log({q: 1, w: 2, e: 3}::size); // => 3
let dict = {q: 1, w: 2, e: 3};
dict::size = 2;
log(dict); // => {q: 1, w: 2}; |
@zloirock Cool! We couldn't really think of a use case for virtual accessors, but this seems plausible. Still, one of the main objections to |
I wanted to write it after this your comment, but forgot :) I think, abstract-references conception should be maintained fully, maybe with changed syntax. |
@zenparsing Private fields proposal looks not very user-friendly. Abstract references and sugar from this thread do the same and some more :) But syntax really should differ from method extraction. |
@zloirock There were a couple of usability issues with abstract references + weakmaps: First, accidental shadowing of the field name: class Point {
private x, y;
constructor(x, y) {
// Oops - parameter "x" is shadowing the private field name
this::x = x;
this::y = y;
}
} I think users coming from other OOP languages would be tripped up by this. Second, WeakMap's class C {
private x;
constructor() { this::x = 0 }
mutateX(value) { this::x = value }
}
let imposter = {};
C.prototype.mutateX.call(imposter, 123);
// imposter now has a private field that it shouldn't The private fields proposal fixes both of these issues. If you can spot specific usability problems with private fields, though, please add them as issues to that repo. Feedback is much appreciated! : ) |
@zenparsing I did not say anything about |
This repo except abstract references proposal contains note about
private
keyword. November tc39 meeting contain discuss aboutprivate
properties in class literal. Abstract references gives sugar for virtual methods call, but it's too bulky for private methods:I propose add
private
keyword for methods in class literal as sugar for it:The text was updated successfully, but these errors were encountered: