Quote:
Originally Posted by Craggoo
Arrow functions "inherit" context without you having to pass it through via bind.
This is called lexical scoping and that's how practically all modern programming languages work. Even in JavaScript, for everything except "this", this is how scoping works. What JavaScript does with "this" outside of arrow functions is essentially akin to dynamic scoping and used to be more widespread but lexical scoping more or less won the war and no serious programming language designer would consider anything other than lexical scoping as the default choice in 2018.
Quote:
1) If you plan on passing in a this value when you call a function, the function should not be an arrow function because the context you pass in will be ignored.
Caller being able to set context as to the called function's scope isn't something that should still be happening in 2018. This was only ever necessary to emulate class-based OO in JavaScript when methods were indistinguishable from functions and isn't necessary except where class methods (which are by definition not arrow functions) being passed as callbacks.
Quote:
2) In the AWS example, the context will be undefined therefore rendering an arrow function in that example really pointless
This is only true if you accept the old JS function to be some kind of sacred default way and have internalized its idiosyncratic behavior as the right way. Among modern JS programmers, outside of methods and constructors, arrow functions are increasingly seen as the default because that's how all other languages work.
Quote:
I would generally argue against using arrow functions entirely. Imagine a scenario where you have a bunch of nested arrow functions. You would need to track down which context is actually being used (implicit) instead of explicitly binding the context you want (explicit).
How them do you track down how other named variables are resolved? All arrow functions do is that they treat "this" the same way that they treat other variables. There's nothing confusing about "implicit context" - this is just standard lexical scoping, now applied to all variables instead of all variables except "this" for which a weird set of rules is applied. As you can see from the responses here and what not, lexical scoping isn't confusing, "this" is confusing - arrow functions dramatically reduce the confusion and reliance on the special behavior of "this" and bring JS to parity with other modern languages.