-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Static method syntax is unatural #533
Comments
I agree with this. Really the :: makes most sense. |
Ruby uses @@ for class variables, which works pretty well for them and goes very nicely with the current @ notation for instance variables. |
Yes, |
@michaelficarra @TrevorBurnham |
@evilpie Sure, it could be misused, but I don't like having to use the class name every time I want to reference a class property within the class. It's syntactic sugar, and it means I'm less likely to have to do a find-and-replace every time I decide to rename a class. I think that making refactoring easy should be a high priority for a language. |
surely @@ can be expanded to this.constructor ? |
I think it would implementing it in function easier, but it would again be different in how it behaves for classmethods. @@ should yield the name of the current class, function, object |
Sorry, folks -- this one is a Languages like Ruby that can't have data on the same level as instance methods need storage on the class object for tagging classes with extra metadata, but in JS putting it on the prototype is a perfectly fine location. |
Is this still something that is out of the question? Classes weren't that common in use before, but nowadays i find they are everywhere, and I am almost never having to access the prototype, but rather the static methods on the class from within a class instance. This pattern is really encouraged with react... Thoughts? |
I’m not sure we need another syntax for static methods. What would it be? Keep in mind there are class decorators (#4917) working their way through the ES approval process, and we’ll probably need |
My suggestion was to keep static method declaration as is, and use @@ for
this.constructor shortcut, and an alternative syntax for class decorators,
given that @ has special meaning for coffeescript. There are plenty of
alternative decorator syntaxes in the decorator discussion thread.
…On Fri, May 11, 2018, 2:03 AM Geoffrey Booth ***@***.***> wrote:
I’m not sure we need another syntax for static methods. What would it be?
Keep in mind there are class decorators (#4917
<#4917>) working their
way through the ES approval process, and we’ll probably need @@ for those.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#533 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAOFkOuita-9HBBdDLDr7mPEiHr2bObXks5txSmogaJpZM4T6iPf>
.
|
This was already discussed on irc and in that issue. This ticket is here until someone finds a better alternative or we accept the current way.
I dont like the @ syntax, because in class context it refers to 'this', wich can only exits in an instance, and the @ for staticmethod has explicitly nothing to do with the instance.
Here are a few ideas, although i think these arent perfect solution.
The text was updated successfully, but these errors were encountered: