syntax - What does it mean equal and greater-than sign (=>) in Javascript? -


in meteor whatsapp example project file "=>" used, webstorm ide detect error. can't find docs syntax.

chats.foreach( chat => {   let message = messages.findone({ chatid: { $exists: false } });   chat.lastmessage = message;   let chatid = chats.insert(chat);   messages.update(message._id, { $set: { chatid: chatid } }) }); 

github repository bootstrap.js file here

what "=>" ?

i downvote question, googling answer proved surprisingly difficult if don't know called. can see in links in comments, that's fat arrow function (sometimes referred arrow function).

there confusing aspects of arrow functions, i'll hit highlights:

normal functions have this pointer set depending on context: functions called new have set newly-created object, functions called methods have bound object method called from, otherwise bound undefined or global object (depending on 'strict mode' pragma), , can of course set function.prototype.bind et al.

but arrow functions have no binding this pointer created runtime (nor can specified via function.prototype.bind), meaning gets lexically looked through scope chain resolution other var. mdn article @ best confusing on point (see link above).

additionally, arrow functions have implicit return, return value automatically last evaluated expression in function body.

arrow functions have no arguments psuedo-array. can use es 6 rest parameters instead.

for functions of arity 1, parens around parameter may omitted.


Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -