So with ES6 we have arrow-functions which - next to maintaining the this
context - increase readability in my opinion.
Common Samples:
[...].map(item => item.attr)
or [...].reduce((a,b) => {...} )
.
So I am asking myself: Is it considered good practice to use these arrow functions instead of function(){...}
. Because that is what you see nowadays.
My personal 2 cents on this:
- Seen from a view of readability and maintainability I'd like to generally use arrow functions
- Seen from a technical and contextual view I consider using arrow functions should be an exception and not the norm as it can lead to unwanted behaviour. E.g.: Changing the context of an arrow functions is senseless:
(()=>{}).apply(window)
will have absolutely no effect. That said: A library that needs a specific context could be easily brought to its knees by arrow functions.
This is just a small extract of my thoughts. I have this certain paranoia everytime I am using arrow functions as I feel it is a wrong thing to do when you do not actually need to remain in that context.