Consider specifying functions as member functions instead of class fields #2424
mwaibel-go
started this conversation in
Ideas
Replies: 1 comment 2 replies
-
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Consider the use case of extending a Mark with a subclass. If I wanted to only add functionality to the render function, the idiomatic way in class-based JavaScript would be:
However, this isn’t possible because render is declared as a property on RenderableMark, so it doesn’t live on the prototype chain, but is instead copied to each instance, even subclasses’ instances (the way I understand it; I’m no TS or JS guru myself). Therefore it isn’t accessible via super.render. This forces us to use this (IMHO) rather unwieldy function definition:
I understand this is idiomatic to the hardened JavaScript veteran, but I would personally prefer the first definition.
Beta Was this translation helpful? Give feedback.
All reactions