0

The following code:

  angular.module('socially').controller('PartiesListCtrl', function ($scope) 
  {
    $scope.helpers({
          parties: () => {
            return Parties.find({});
          }
    });
  });

demo at Angular Meteor Tutorial

Can't understand the syntax used for parties: object. Why is => used ? Is there more explanation for this kind of anonymous function.

aj_blk
  • 304
  • 2
  • 6
  • 16

1 Answers1

4

This is an arrow function, new syntax from ES2015 standard which was accepted this year. Not only arrow functions are shorter in declaration and sometimes looks nicer, they also share binding context with their surrounding code

!function() {
  this.name = 'global';

  var nonArrowFunc = function() {
    console.log(this.name); // undefined, because this is bind to nonArrowFunc
  }

  var arrowFunc = () => {
    console.log(this.name); // this taken from outer scope
  }


}();

You can read more about arrow functions here and here and here

Vlad Miller
  • 2,255
  • 1
  • 20
  • 38