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
Call static method without repeating the class name #7673
Comments
A good IDE should be able to rename/refactor your class without any problem, especially if the refactor is in the same class. |
You can walk to most places instead of driving there, that is not really a reason for not using a car. |
You should be able to write |
+1 Not to mention Java where you can call a static method just by it's name (from within the same class of course). This will make the code much more readable. |
@DanielRosenwasser it is usual for me to call static methods/props from instance methods, but |
@bloadvenro +1 |
+1 |
+1 |
In my opinion, this feature is really important to improve the readability of the code. Although the ability to refactor the code more easily is also welcomed, of course. When you have to add a class name before a method call, a statement that usually takes 1 line, takes 2 (or even more). Specially if the names of your class, method or arguments (or all them) are not trivial, and you've to restrict the line length to 80 characters. With regard to the implementation of this feature, I would love to be able to omit the class name entirely, as in Java. But I guess that it could lead to confusion in JavaScript; because one wouldn't know if the code is calling a static method or an independent function. But that already may happen with instance methods, if you set the option I also like the idea of the
These values could also be named as: This way, we all could choose the option that better suited our needs. |
When I create a static method, the only way to call it seems to be through the actual class name:
MyClass.staticMethod
. It would be great if there was a way to call the static method without repeating the class name, it would be less error prone when you later decide to rename the class.A few suggestions:
self.class.staticMethod
orself.type.staticMethod
orSelf.staticMethod
In other languages you can do it like this:
$this->staticMethod();
or$this::staticMethod();
self.__class__.staticMethod()
self.class.staticMethod
[[self class] staticMethod]
self.dynamicType.staticMethod()
The text was updated successfully, but these errors were encountered: