-
Notifications
You must be signed in to change notification settings - Fork 2
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
Prototype Placement of Private Methods. #2
Comments
Agreed on the immediate point. On the other point, I find it attractive in the abstract to have class-scoped declarations. But I am at a loss for a good syntax. Whatever the syntax is, it should treat all declarations the same way. Making a special case for function declarations seems bizarre. |
It seems to me that we already have a perfectly fine syntax for class scoped declarations -- it is exactly class X {
function helper() {);
const mask=0x00ff00ff;
leader() {
helper();
}
let [x,y]=aPoint;
static supremeLeader() {
helper()
}
class inner {}
} |
Awesome! Yes, we should push for this. But separately from this proposal, as you way. Your example's indentation is weird. |
What if we said that the semantics of a private method which is not 'own' is that it would be in an immutable private slot, and an 'own' private method would be in a mutable private slot? This would make the values of the immutable methods into a sort of 'fake prototype', not reified at all (they would still be instance slots), but similar to prototype methods in that their value is shared by all instances. |
In my early work on "private" methods, I desperately wanted class-scoped function declarations, but there are some parsing issues. Consider this token stream:
When you read the |
Any ambiguities in addition to async function/method? While it's unfortunate to have such a special case, the easy solution would be to simply not allow async function declarations within a class definition. Assuming that we do allow Another approach, that unfortunately we are probably too late for, would be to forbid (via a look ahead restriction) the use of the identifier |
see tc39/ecma262#832 |
@bakkot Is this lookahead worse than what we need for the currently proposed property syntax? IIRC you ran into some pretty hairy cases involving somewhat deep lookahead, but were able to implement it reasonably in the V8 parser. I don't think the syntax has changed since you did that work, either. |
The current proposal already requires two tokens of lookahead to distinguish between a static getter and a static field named class A {
static get p() {}
} vs class A {
static get = 0;
} Assuming we don't have class A {
static async function f(){}
} vs class A {
static async function(){}
} |
It's been a while since I've done any parser work, but I don't think the Whereas for the |
Private methods on the prototype are pretty useless as there is no convenient way to reference them. Consider:
Class declaration scoped function declarations are probably more convenient and useful than either prototype private methods or static private methods. Eg:
For this reason, I think we should excluded prototype placement of private methods from this proposal and possibly push for the inclusion of class scoped function declarations.
The text was updated successfully, but these errors were encountered: