3 ms·
and now you are defining you whole class inside that return {}. Do you honestly find this more readable?
by 21 8y ago
and now you are defining you whole class inside that return {}. Do you honestly find this more readable?
- keb_ 8y agoThis is similar to the Revealing Module Pattern in Learning JavaScript Design Patterns: https://addyosmani.com/resources/essentialjsdesignpatterns/book/#revealingmodulepatternjavascript https://addyosmani.com/resources/essentialjsdesignpatterns/b... I think it's perfectly readable, and it requires no more language hacks that obfuscate the JavaScript underlying `class` syntax sugar.
- eadmund 8y agoThis is why macros and a homoiconic language are such a good thing: you can add syntax sugar to have something which is both straightforwardly implemented and readable.
- lioeters 8y agoI often use a functional style as the OP's above, instead of classes, but I wonder about performance hit. Calling it often (like many "instances") and creating new functions every time seem less efficient that inheriting methods via prototype.
- Roboprog 8y agoIf I were to create 300 instances of something with actual func^H^H^H^H methods attached, rather than 3 instances, I would probably look into creating a prototype and coping with the perils of “this” usage, but otherwise, I’m not going to lose much sleep about it.
- Roboprog 8y agoYes, especially if the result is only used in a small number of nearby places, which is usually the case. My IDE can easily infer the properties of such objects, as well as display the JSDoc for such properties.