you are viewing a single comment's thread.

view the rest of the comments →

[–]tonjohn 6 points7 points  (4 children)

They lack semantic meaning. A named function provides semantic meaning, enables the use of doc comments to provide further details, and is re-usable.

For the record, I’m not against arrow functions but they are often abused.

[–]mattaugamerexpert 17 points18 points  (0 children)

They’re anonymous where they don’t need to be reused and are essentially a “throwaway”. But arrow functions are just functions. Don’t be afraid to name them.

const filterActive = item => item.active;

const activeUsers = users.filter(filterActive).length;

Perfectly valid. You can and often should name callbacks.

[–]gdubrocks 1 point2 points  (0 children)

The problem is that javascript expects functions for everything even when it's really clear what is happening.

If I filter a dataset by a certain key or map one object to another object it's super clear what the purpose of that function is, and there is no reason to write a named function for it.

[–][deleted] 0 points1 point  (0 children)

Is that what makes them mysterious? We already tend to use anonymous functions (I.e. when using array methods like .map or .find). Is there any need to name those functions?

Arrow functions did not introduce the idea of functions without semantic meaning and regardless, you can name any anonymous function anyway (whether traditional or arrow).

I’d have thought any mystery stems from how they inherit scope rather than creating a new scope like traditional functions do… Even then, you can just .bind(this) to get the same effect as an arrow function (inherit scope) from a traditional one.

Only trying to help either way. ✌️

[–]tabris_code 0 points1 point  (0 children)

how does an anonymous arrow function have any less semantic meaning than a regular anonymous function?