I’m working on refactoring my JS Calculator project to ES6 just to help solidify my memory of ES6. So I’m going around converting functions to arrow functions, and for a few that breaks it. Several of them have “
this” in them, and I know the whole point of arrow functions is that they handle
this differently, so maybe that’s it, but I’m not getting a handle on it.
- Here’s the original, ES5 version: http://codepen.io/AbdiViklas/pen/GjdrZQ
- and here’s the refactor: http://codepen.io/AbdiViklas/pen/dNxGpN
Some areas of interest:
- the “operation” function beginning on line 34: the “display an E if dividing by 0” part works, but the
console.logI added to line 42 (inline, to keep the line numbers the same between the two versions) shows that that part doesn’t work. Is this big mess of
elses just to complicated for an arrow function?
- The function on li 93 breaks when I turn it into an arrow function. This has a
- The function on li 144 is already broken, presumably because it calls the “operation” function above.
I’d also appreciate any other suggestions for things to consider in refactoring and cleaning up that I haven’t thought of. Thanks!