It's quite frustrating to have to write this.myMethod()
or ClassName.myMethod()
instead of just myMethod()
. Especially when dealing with a stateless utility function that doesn't need direct access to fields.
Take a look at this example:
function method1() { }
class App {
main() {
method1(); // I wish I could just use this
App.method2();
}
private static method2() {
// Stateless and doesn't require field access
}
}
I often ponder whether using a global function instead of a private static method (or vice versa) would be more beneficial. Any insights on this issue?