0

I don't achieve to get any information about () => {}

An example in Meteor:

Meteor.startup(() => {
  // code to run on server at startup
});

What is its function?

Thank you so much.

  • arrow syntax as per es6 standards. That's where you `this` is available and need not to mention and basically you have to say a new syntax for callback anonymous functions. – Jai Jun 21 '16 at 17:28
  • This is a shorthand for anonymous function in es6. Also called as Arrow function. You can get more information over here.Arrow functions capture the this value of the enclosing context. https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Functions/Arrow_functions – rahil sharma Jun 21 '16 at 17:32

1 Answers1

-2

That is ES6 short hand for an anonymous function definition in javascript.

Short hand for:

Meteor.startup(function() {

});

Specifically in this case, it's a callback that is invoked once the startup method for Meteor is run.

The benefit with using => is that this is bound at the appropriate scope.

Alan
  • 42,055
  • 16
  • 107
  • 130
  • More like shorthand for `function() {}.bind(this)`.. – Florrie Jun 21 '16 at 17:29
  • What is wrong with this answer guys? – Jai Jun 21 '16 at 17:31
  • 1
    @Jai as was explained, the two functions are not equivalent, because `this` has a different meaning within them. Which is actually a huge difference. – Matis Lepik Jun 21 '16 at 17:32
  • @MatisLepik Where do you see `this` in the question? and yes Alan needed to mention that okay!!! – Jai Jun 21 '16 at 17:33
  • It's only a "huge" difference if you need proper binding of `this.` – Alan Jun 21 '16 at 17:34
  • 1
    @Jai The question was about the arrow syntax, which `this` obviously pertains to. It wasn't in the question because OP doesn't know what an arrow function is, obviously he's not going to know to ask specifically about `this`. Nevertheless it is an important part of the answer, and this person's answer implied that the two are functionally identical, which is incorrect. – Matis Lepik Jun 21 '16 at 17:35
  • @MatisLepik correct! agreed.....!!! – Jai Jun 21 '16 at 17:36