-
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
Use cases for own methods #6
Comments
It seems just the opposite to me. Prototype placement methods are,. by far, the most common kind of class element and the concept that (prototype) methods don't have a keyword prefix is already well established by ES2015. Anybody prefixing own in front of all of their methods for no reason clearly would have a misunderstanding of who classes work. The whole point of this proposal is to provide an easily learned, orthogonal syntax that minimizes that confusion. Basically, non-prefix means shared by all instances and |
Well, I can understand it well, but imagine someone who comes from the current Babel syntax, and sees, "OK, TC39 wants me to put This could also be someone who is coming from another programming language which doesn't give you the option of putting things in all these various places (I can't think of any other language that has a convenient syntax for both own and prototype/class methods like this); the distinction/motivation may feel subtle for them and so they might not get this analogy, thinking the object system will just figure it out which things are on the class and which are on the instance (as in other languages where all methods are on the class, and all non-static member declarations on the instance). I'm not saying we should design the language exclusively to suit this sort of analysis, but I think it will come up. The fact that you put Anyway, I'm thinking about this as a cost-benefit analysis. If this is something users will find solves their problems, it could pay for its cost of potential user confusion. So I opened this thread to collect more use cases. |
No, that isn't the reason only As discussed in #2 class lexically scoped function declarations are probably a better solution for use cases where prototype placement "private methods" might be considered. |
Well, I tried to suggest one via this example from the proposal: class {
own #callback(){} //a private instance method
...
setCallback(f){this.#callback=f}
} This is essentially a function valued per instance private field that is initialized to some default function value. However, on a per instance basis the function value of the field can be set to some other function value. Using public properties, the default could be provided via a prototype method which is over-ridden only on those instances that set the property to something other than the default. But that won't work using private fields because instances don't inherit access to prototype private fields. |
Yes, I agree that, unless you do something different, not based on an actual prototype, such as lexically scoped functions or an ad-hoc semantic as described in https://github.com/tc39/proposal-private-fields/blob/master/METHODS.md , private methods must be own. I guess one related question is, what do users' intuitions tend to be? This affects which would feel more exceptional/inconsistent. |
I like the aesthetics of having own methods to "complete the grid" and make an orthogonal system, but I'm wondering about the usage of this feature. I've heard from @sebmarkbage (please correct me if I'm misunderstanding) that own methods are useful for a couple things:
method = () => {}
)Any other usage scenarios? Collecting these might help us feel more comfortable about the ergonomics. As it is, I'm a little worried about how useful the feature will be besides providing some measure of orthogonality (in a grid which already has other holes).
I'm also worried that much of the usage might be people writing
own
before methods for not much reason, just because they have to write it in many other places in classes, and it has very similar behavior from a casual observation.The text was updated successfully, but these errors were encountered: