Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
How was I supposed to know it was called "fat arrow"?
You would think googling for "=>" would tell me what it was. -
port2211078yThe reason why it's so nice is because let's say you have some function that takes parameter foo, you can write
foo => foo + 1
Which returns foo + 1, the same as
function(foo) {
return foo + 1
}
It helps reduces boilerplating -
@port22 that code would be using - >, using fat arrow passes this as a function parameter, or maybe that's Coffeescript specific?
-
@port22 Thanks port22 :). See that's all I wanted. A polite answer :). I know a lot, but not everything :D
-
@port22 my bad, I could've sworn I saw Coffeescript somewhere here. More coffee is needed I think.
-
It's a little different than a regular function because it doesn't change the binding of 'this' to the function itself.
I hope that made sense...JS can be confusing. -
snypenet2358yFat arrow functions? I always heard them called lambda expressions or anonymous functions.
-
ardinent1148y@port22 Can you give a contextual example? There's no assignment operator in yours and I'm not seeing the context of where the value is 'returning'...
foo = 1;
foo => foo + 1;
console.log( foo ); // 1? -
nmunro31908y@ardinent cos you define a function but never use it.
let foo = 2;
inc = a => a+2;
foo += inc();
console.log(foo);
Also when in doubt for language things, if you don't know what something is card, download the PDF language spec, search for the operator and find out what it's called that way. -
ardinent1148y@nmunro This seemed to be a thread discussing the usage of the operator, so I thought enquiring about it might share it's usage with more followers.
Another question... Should you not be passing a value in your inc() call? -
nmunro31908y@ardinent Yes, yes I should, I also intended to use 1 not 2, guess I shouldn't code before coffee...
-
ardinent1148y
-
nmunro31908y@ardinent however...
It only implicitly returns something if the function is one line...
That is to say
Foo = a => {
a++;
return a + 5;
}
Must have the return statement in multiline functions
So node developers. Can anyone explain to me what the hell the "=>" operator is? Because I cannot find anything about it online.
undefined