I have a problem with understanding ES6 arrow function syntax. Why this code does not work:
Meteor.publish('parties', (options, searchString) => {
...
})
But this one works:
Meteor.publish('parties', function (options, searchString) {
...
})
I have a problem with understanding ES6 arrow function syntax. Why this code does not work:
Meteor.publish('parties', (options, searchString) => {
...
})
But this one works:
Meteor.publish('parties', function (options, searchString) {
...
})
The primary difference between example one and example two is that example one uses the calls scope while example two uses Meteors scope. If I had to make a guess it would be that it is not working because you are using this
and expecting a different scope. Here is a quick example to demonstrate this functionality...
(function () {
var Example = (function () {
function Example() {
setTimeout(function() {
console.log(this); //this === window
}, 0);
setTimeout(() => {
console.log(this); //this === test
}, 0);
}
return Example;
}());
var test = new Example();
}());
You can read about the specifics here