ES6 arrow functions

torayeff

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) {
...
}) 
Marie

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

es6 arrow functions debugger statement

From Dev

Are ES6 arrow functions incompatible with Angular?

From Dev

ES6 arrow functions not working on the prototype?

From Dev

javascript es6 double arrow functions

From Dev

Argument types in functions versus in arrow functions in ES6

From Java

Methods in ES6 objects: using arrow functions

From Java

Is it possible to export Arrow functions in ES6/7?

From Java

Using _ (underscore) variable with arrow functions in ES6/Typescript

From Dev

Immediate function using JavaScript ES6 arrow functions

From Java

When should I use `return` in es6 Arrow Functions?

From Dev

How to run ES6 code with arrow functions in Safari?

From Dev

What does "this" refer to in arrow functions in ES6?

From Dev

How to use ES6 arrow functions with promise binding (bluebird)

From Dev

Official information on `arguments` in ES6 Arrow functions?

From Dev

Explain effect of ES6 class constructor and arrow functions

From Dev

jQuery .each() function with ES6 arrow functions

From Dev

Jump to ES6 arrow functions in Sublime text editor

From Dev

Can't use fat arrow functions (ES6) in react

From Dev

This not working as expected in nested arrow functions in ES6

From Dev

React / ES6 - Why calling a function inside another only works with es6 arrow functions?

From Dev

ECMAScript 6 arrow functions

From Dev

Compiling ES6 arrow functions to Es5 using Babel.js

From Dev

When should I use a return statement in ES6 arrow functions

From Dev

ES6 in NodeJS: Arrow functions in object literal, what is the returned 'this' value?

From Dev

Why we have to wrap throw with brackets in es6 arrow functions

From Dev

How is .call supposed to work for ES6 Arrow Functions (according to the standards)?

From Dev

D3.js event listeners cannot access "this" when ES6 arrow functions are used

From Dev

Do ES6 arrow functions still close over "this" even if they don't use it?

From Dev

Using ES6 Arrow Functions in Node 0.11 w/ Foo.prototype

Related Related

  1. 1

    es6 arrow functions debugger statement

  2. 2

    Are ES6 arrow functions incompatible with Angular?

  3. 3

    ES6 arrow functions not working on the prototype?

  4. 4

    javascript es6 double arrow functions

  5. 5

    Argument types in functions versus in arrow functions in ES6

  6. 6

    Methods in ES6 objects: using arrow functions

  7. 7

    Is it possible to export Arrow functions in ES6/7?

  8. 8

    Using _ (underscore) variable with arrow functions in ES6/Typescript

  9. 9

    Immediate function using JavaScript ES6 arrow functions

  10. 10

    When should I use `return` in es6 Arrow Functions?

  11. 11

    How to run ES6 code with arrow functions in Safari?

  12. 12

    What does "this" refer to in arrow functions in ES6?

  13. 13

    How to use ES6 arrow functions with promise binding (bluebird)

  14. 14

    Official information on `arguments` in ES6 Arrow functions?

  15. 15

    Explain effect of ES6 class constructor and arrow functions

  16. 16

    jQuery .each() function with ES6 arrow functions

  17. 17

    Jump to ES6 arrow functions in Sublime text editor

  18. 18

    Can't use fat arrow functions (ES6) in react

  19. 19

    This not working as expected in nested arrow functions in ES6

  20. 20

    React / ES6 - Why calling a function inside another only works with es6 arrow functions?

  21. 21

    ECMAScript 6 arrow functions

  22. 22

    Compiling ES6 arrow functions to Es5 using Babel.js

  23. 23

    When should I use a return statement in ES6 arrow functions

  24. 24

    ES6 in NodeJS: Arrow functions in object literal, what is the returned 'this' value?

  25. 25

    Why we have to wrap throw with brackets in es6 arrow functions

  26. 26

    How is .call supposed to work for ES6 Arrow Functions (according to the standards)?

  27. 27

    D3.js event listeners cannot access "this" when ES6 arrow functions are used

  28. 28

    Do ES6 arrow functions still close over "this" even if they don't use it?

  29. 29

    Using ES6 Arrow Functions in Node 0.11 w/ Foo.prototype

HotTag

Archive