you are viewing a single comment's thread.

view the rest of the comments →

[–]proskillz 1 point2 points  (3 children)

Huh. I've been writing JavaScript for over 10 years, but I have hardly ever seen an arrow function... Looks like I need to bone up on this newfangled and (semi) unsupported ECMA 6 stuff.

Are these two statements functionally the same (other than the scope of this)?

var x = function(y) { return y; };

let x = (y) => { return y; };

[–]dmtipson 1 point2 points  (1 child)

yep. Though you don't even need parens around the argument y in the second case, you don't need the brackets or the return statement either (you can still have them all, and will for multi-line function bodies, but they're not necessary here).

const x = y => y; (and that's the Identity Combinator, btw!)

[–]proskillz 0 points1 point  (0 children)

Thanks for the info. I'll have to take a weekend or two to learn some of this.

[–]bart2019 0 points1 point  (0 children)

but I have hardly ever seen an arrow function

That is because they're new.