3 ms·
It's absolutely useless anyway unless you're trying to slightly optimize cpu and memory usage for at least hundreds of instance creations. Typically this scenar
by boubiyeah 10y ago
It's absolutely useless anyway unless you're trying to slightly optimize cpu and memory usage for at least hundreds of instance creations. Typically this scenario would be found in libs, not in application code.
I completely ignore this, prototypes, classes, Function.prototype.bind, etc. Code is much cleaner and easy to follow for devs of all skill level.
Also, even if you like these features, var that = this is unneeded if you use a transpiler and have access to the more modern JS constructs like arrow functions.
- sideshowb 10y agoHow do you factor out "this" in cases where methods and instance data logically belong together?
- beaconstudios 10y agoIf you're completely getting rid of "this" references then you're probably following a functional style and will keep data and functions separate, passing pure data as arguments rather than combining data and functions into classes.
- boubiyeah 10y ago1) Either use a functional style like beaconstudios said where it's perfectly normal to separate the data and the processing. 2) Or if you want to keep an OO style, use the module pattern with private functions closing over the data.
- cerved 9y agoUsing an object factory and referencing the object within the factory's lexical scope
- deleted 10y ago[deleted]