4 ms·
Working with classes in ES6 is such a relief. My only complaint is that if you save a method as a variable or pass it to another function, it'll just be a funct
by raziel2p 11y ago
Working with classes in ES6 is such a relief. My only complaint is that if you save a method as a variable or pass it to another function, it'll just be a function with its own scope (`this` won't reference the class instance, but instead the method function).
Easily "fixed" if you remember to put `.bind(this)` everywhere, though.
- hokkos 11y agoOr use : myMethod = (arg) => {return this.value + arg;} With es7.classProperties in babel. https://babeljs.io/docs/usage/experimental/ https://babeljs.io/docs/usage/experimental/
- savanaly 11y agoSample code from just this afternoon: const typeMap = { 'i-text': this.processText.bind(this), 'image': this.processImage.bind(this), 'rect': this.processRectangle.bind(this) }; Really annoying if you ask me, though I understand why it had to be this way.