I am new to learning objects and classes in Javascript. I was just wondering, why would you attach a static method to a class, like so:
class MyClass {
static myFunction(){
console.log('foo');
}
}
When you can just declare a regular, custom function outside of the class like one usually does?
function myFunction() {
console.log('foo');
}
MyClass.myFunctionvsnew MyClass().myFunction. If you do not need an instance of the class for the logic in the method, why require one? Though the OP is comparing a class method to a normal method. Which also involves the whole concept of OO programming, and code organization.