4 ms·
Despite writing ES6 with arrow functions, I find that I prefer writing `const self = this` than relying arrow-function lexical scoping. Maybe it will change ove
by crgwbr 10y ago
Despite writing ES6 with arrow functions, I find that I prefer writing `const self = this` than relying arrow-function lexical scoping. Maybe it will change over time, but for now that way seems to make he intent far clearer and less likely to mess up in a future refactoring.
- z3t4 10y agoTo make it more clear, you can use names. For example: function Car() { const car = this; function foo() { car.engine = "v8"; // vs self.engine } }
- nkkollaw 10y agoNot much clearer, if not less. var self = this; and var that = this; are the standard way and the intent is understood right away.