-
Notifications
You must be signed in to change notification settings - Fork 3
Should we do infix :: instead of private methods (and other things)? #38
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
Comments
For :: to do the job of -> for hidden methods, we'd replace the hidden method declaration with a lexical function declaration as previously proposed. The first hidden method example at class Spaceship {
function flyTo(destination) {
// Blast off!
}
flyToMoon() {
this::flyTo(Location.MOON);
}
} |
@erights Using this approach, what would instance var references look like? |
I rather like this — when I need private methods currently, I do exactly this but with One q: if the syntax is |
Presumably, that's how it would work. That points to my main concern: that we would have two similar-but-different function definition forms inside of class bodies. @erights I think I understand your concern: Is that what you're thinking? 🤔 |
@erights Just kicking some ideas around, purely for fun: What if we had an extension declaration form:
For example: extension {
x() {}
get y() {}
} This declaration form would introduce "hidden" bindings into the enclosing scope in a parallel namespace (similar to the way our current hidden methods work). Using an extension accessor: extension {
get fullName() {
return this.first + ' ' + this.last;
}
}
({ first: 'Kevin', last: 'Smith' })::fullName; // 'Kevin Smith' Extension declarations would also be allowed inside of classes: class Person {
constructor() {
this.first = 'Kevin';
this.last = 'Smith';
}
sayHello() {
return `Hi, I'm ${ this::fullName }`;
}
extension {
get fullName() {
return this.first + ' ' + this.last;
}
}
} Then I suppose that instance var references would be rationalized as automatically generated extension accessors within the class body. I have no idea how you'd import and export these things, though 🙄 Again, just playing around for fun! |
See tc39/proposal-pipeline-operator#107
The text was updated successfully, but these errors were encountered: