Arrow Functions
No binding
Arrow functions cannot be bound to objects. The this
variable's value will always be the one of the parent closure.
Example with Array.filter
and Array.map
Array.filter
and Array.map
One-liner
In most cases, callbacks are just simple one-liners.
In this case, curly braces {}
and the return
statement can be removed.
If the arrow function only takes one parameter, the parentheses ()
can be removed.
In case of variable name shadowing, try to avoid single letter variable names or generic names.
filter(u => u.id === user.id)
filter(it => it.id === user.id)
Prefer the _
prefix to mark the difference between the local variable and the one from the parent closure.
filter(_user => _user.id === user.id)
Last updated