3 ms·
What's the better alternative?
by wongarsu 9y ago
What's the better alternative?
- reificator 9y agoIf I understand their concerns correctly, they would prefer this: > window.addEventListener('online', this.checkStorage);
- allover 9y agoThat wouldn't work, you'd need to at least use bind() so that the `this` keyword within `this.checkStorage` references the right thing, e.g. window.addEventListener('online', this.checkStorage.bind(this));
- mikewhy 9y agoThe language can do that for you: class Foo { checkStorage = () => { // Do check storage stuff here } } And the language will take care of binding the function. (Really, it's just doing `this.checkStorage = this.checkStorage.bind(this)` in the constructor).
- allover 9y agoThat's not in 'the language' yet :)
- deleted 9y ago[deleted]
- TomMarius 9y agoUsing bind and saving a reference to the bound function one level up, not creating a new one each time
- deleted 9y ago[deleted]