user1665355
user1665355

Reputation: 3393

Arrow function in this.helpers

I wonder if someone could explain the difference between:

$reactive(this).attach($scope);
this.helpers({
   parties: () => { //arrow function definition
     return Parties.find({});
   }
});

and

let reactiveContext = $reactive(this).attach($scope);    
reactiveContext.helpers({
  parties: function() { //function definition
    return Parties.find({});
  }
});

I have read about arrow function and how it handles this (i.e. why the `this` is not work in arrow function of ES6?)

But in this case, it should not matter how we define parties in helpers? Because this is nowhere present in this example. Am I wrong?

I understand that arrow function is useful in the context of:

this.subscribe('parties', () => {
  return [
    {
      limit: parseInt(this.perPage),
      skip: parseInt((this.getReactively('page') - 1) * this.perPage),
      sort: this.getReactively('sort')
    }
  ]
});

where i.e. this (in this.perPage) is bound to enclosing context.

Upvotes: 0

Views: 70

Answers (1)

Paul
Paul

Reputation: 141887

There is no difference, when this isn't used inside the function.

They will behave identically.

Upvotes: 2

Related Questions