When and why not to use arrow functions
For part one, where I go into a detailed description of arrow functions, reasons to love them, and how to use them, click here:
https://medium.com/@justynakuchta/reasons-to-love-javascript-arrow-functions-23655710fd38
When to avoid them?
It is worth noting that the => arrow function is not suitable as a general purpose replacement for all function functions in your JS code. There are several reasons, and the topic deserves its own post. In short:
Arrow function expressions are ill suited as methods, and they cannot be used as constructors.
this in a construction invocation is the newly created object. When executing new MyFunction(), the context of the constructor MyFunction is a new object: this instanceof MyFunction === true.
Notice that an arrow function cannot be used as a constructor. JavaScript implicitly prevents from doing that by throwing an exception.
Anyway, this is setup from the enclosing context and is not the newly created object. In other words, an arrow function constructor invocation doesn’t make sense and is ambiguous.
Let’s see what happens if however trying to: