3 ms·
Fat arrow is used to define a lambda function. The left-hand side of the arrow is argument list (_ is used to indicate lack of used arguments) and the right-han
by mbel 9y ago
Fat arrow is used to define a lambda function. The left-hand side of the arrow is argument list (_ is used to indicate lack of used arguments) and the right-hand side is the function body. It is equivalent to:
var currentUrl = function () { return window.location.href; }
- TheDong 9y agoIt is not the same as that. the fat arrow doesn't change the value of "this" while the function definition does.
- geoelectric 9y agoGiven that "this" isn't referenced in the function, though, it's practically equivalent.
- simlevesque 9y agoI think one is more efficient memory wise but I'm not sure which one.
- thephyber 9y ago> _ is used to indicate lack of used arguments Note that this is a convention, not a requirement for the syntax (like in some other languages). I've spent at least a few mins troubleshooting why `_.map` (from `lodash` npm module) didn't work inside of a fat function while fixing another developer's defect. If you use `_` as a valid const/variable identifier anywhere in your codebase, I would recommend you ditch `_ => alert(1)` for something more obscure like `ø => alert(1)`