Migrating to Arrow function from Normal function JS

Ramzan Chasygov

In my project, I don't wanna use construction function () {}, instead of that I wanna use () => {} or () => (). Code below. In first example I can see this, in second case this undefined. So I wonder, Is it possible way to make () => {} see this? I tried to use () => {}.bind(this) did not work and ({ context: this }) => {} did not work either.

// Example 1
describe('Currency converter', () => {
  it('should be shown on the page', function () {
    console.log(this); // { bla: ..., blabla: ... }
    return this.browser
      .url('/')
      .keys(['currence', '\uE007'])
      .isExisting('.converter-form')
      .then((exists) => {
        assert.ok(exists, 'currence did not show');
      });
  });
});

// Example 2
describe('Currency converter', () => {
  it('should be shown on the page', () => {
    console.log(this) // undefinded
    return this.browser
      .url('/')
      .keys(['currence', '\uE007'])
      .isExisting('.converter-form')
      .then((exists) => {
        assert.ok(exists, 'currence did not show');
      });
  });
});

Ben West

No! Arrow functions don't have a their own value for this, even if you try to bind them. You have to use the long form.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Syntax for async arrow function

From Dev

Node.js support for => (arrow function)

From Dev

arrow in function name in Clojure

From Dev

Typescript - Arrow Function with Parameters

From Dev

Arrow function context in node.js

From Dev

Calling django template tags from a normal function

From Dev

How can I differentiate between an arrow function, class and a normal function?

From Dev

JavaScript ecma6 change normal function to arrow function

From Dev

Is It possible to export constructor function and some normal function from same module in node js?

From Dev

Istanbul function coverage for arrow function?

From Dev

Executing named `fat arrow` from .then() function

From Dev

Return object from arrow function

From Dev

Arrow function eval preprocessor

From Dev

this.emit() in an arrow function

From Dev

this scope in arrow function prototypes

From Dev

What is double arrow function?

From Dev

simulating javascript function with arrow function

From Dev

How do a normal function and arrow function differ around _proto_ constructors?

From Dev

Problems with date function when migrating from SQL Server to POSTGRESQL

From Dev

Java - stop function from its normal run

From Dev

Call normal javascript function from another document in a react component function

From Dev

Return object from arrow function

From Dev

Arrow function error: Object is not a function

From Dev

Arrow function is not a function

From Dev

Es6 Arrow function to normal js

From Dev

Converting javascript arrow function to a normal function

From Dev

Differences in arrow function and no arrow function in ReactJS?

From Dev

Migrating generic function from Alamofire 3 to Alamofire 4

From Dev

Javascript Convert function to arrow function

Related Related

  1. 1

    Syntax for async arrow function

  2. 2

    Node.js support for => (arrow function)

  3. 3

    arrow in function name in Clojure

  4. 4

    Typescript - Arrow Function with Parameters

  5. 5

    Arrow function context in node.js

  6. 6

    Calling django template tags from a normal function

  7. 7

    How can I differentiate between an arrow function, class and a normal function?

  8. 8

    JavaScript ecma6 change normal function to arrow function

  9. 9

    Is It possible to export constructor function and some normal function from same module in node js?

  10. 10

    Istanbul function coverage for arrow function?

  11. 11

    Executing named `fat arrow` from .then() function

  12. 12

    Return object from arrow function

  13. 13

    Arrow function eval preprocessor

  14. 14

    this.emit() in an arrow function

  15. 15

    this scope in arrow function prototypes

  16. 16

    What is double arrow function?

  17. 17

    simulating javascript function with arrow function

  18. 18

    How do a normal function and arrow function differ around _proto_ constructors?

  19. 19

    Problems with date function when migrating from SQL Server to POSTGRESQL

  20. 20

    Java - stop function from its normal run

  21. 21

    Call normal javascript function from another document in a react component function

  22. 22

    Return object from arrow function

  23. 23

    Arrow function error: Object is not a function

  24. 24

    Arrow function is not a function

  25. 25

    Es6 Arrow function to normal js

  26. 26

    Converting javascript arrow function to a normal function

  27. 27

    Differences in arrow function and no arrow function in ReactJS?

  28. 28

    Migrating generic function from Alamofire 3 to Alamofire 4

  29. 29

    Javascript Convert function to arrow function

HotTag

Archive