Message from JavaScript discussions
June 2017
— Hmm, not sure!
As I understand it class
is just a special function, and assigning a property to an uninstantiated class
should get you the same results as assigning a property to a function definition.
— Uuuh noo
— Which... I have never tried, haha
— It creates a static method
—
class MyClass {
static myMethod () {
return 4;
}
}
equivalent to:
function MyClass() {
};
MyClass.myMethod =
function myMethod() {
return 4;
};
— Except second one can run as a function (without new) as well
— That's the only difference
— Heh, static methods AND instance methods can all be changed at runtime dude
— I see
— For static, that is not something I expected. It seems I know less about class syntax in JS than I thought I did
—
function MyClass() {
}
var myInstance = new MyClass();
MyClass.prototype.foo = () => 'bar';
myInstance.foo(); // 'bar'