I love using arrow functions as anonymous callbacks passed into functions (or promises)! Typically, the scope magic as a part of arrow functions is just what I want in that context.
That said, I try to continue to use braces (even though they are optional for single statements, same for if statements), and also explicitly use the return keyword. That helps with my two big hangups on reading arrow functions.
// ehh...okayletsquare=(x)=>x*x;// me likeyletsquareBetter=(x)=>{returnx*x;}// now we're talking!// I mean, I don't know why you'd need to asynchronously get a number...// but here it is:letxSquared=-1;asyncGetANumber().then((x)=>{xSquared=x*x;}));
In almost any other situation (i.e. functions defined in a class, or as part of another object, or gasp globally), I use standard function syntax.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I love using arrow functions as anonymous callbacks passed into functions (or promises)! Typically, the scope magic as a part of arrow functions is just what I want in that context.
That said, I try to continue to use braces (even though they are optional for single statements, same for if statements), and also explicitly use the
return
keyword. That helps with my two big hangups on reading arrow functions.In almost any other situation (i.e. functions defined in a class, or as part of another object, or gasp globally), I use standard function syntax.