Skip to content

arrow function brokes this keyword #730

Closed

Description

@007lva

this works:

work

This doesn't work:
notwork

why?

Activity

  1. sebmck commented on Feb 9, 2015

    @sebmck
    Contributor

    Top level this is undefined ES6 modules as they're implicitly strict mode. Arrow functions inherit the outer this. Expected behaviour.

  2. fkling commented on Feb 9, 2015

    @fkling
    Contributor

    Put differently: If you want a function with its own this value, you cannot use an arrow function.

  3. sebmck commented on Feb 9, 2015

    @sebmck
    Contributor

    Yeah, I phrased that terribly. Arrow functions aren't synonymous with normal functions. You can check out more about their usage here.

  4. developit commented on Feb 9, 2015

    @developit
    Member

    Summary: arrows are awesome

  5. 007lva commented on Feb 9, 2015

    @007lva
    Author

    Oh, thank you very much, this is very instructive 😃

  6. dashed commented on Feb 21, 2015

    @dashed
    Contributor

    @sebmck I'm wondering if babel can "warn" the user if this is transformed to undefined as s/he may unintentionally misused the arrow function? Which is likely the case...

  7. sebmck commented on Feb 21, 2015

    @sebmck
    Contributor

    @dashed I wish, #562.

  8. dashed commented on Feb 21, 2015

    @dashed
    Contributor

    @sebmck Hmm. What about warning of the misuse of this within just arrow functions?

  9. sebmck commented on Feb 21, 2015

    @sebmck
    Contributor

    @dashed It would only catch the top level case and adding warning messages is a slippery slope.

  10. added
    outdated
    on Jul 23, 2018
  11. locked as resolved and limited conversation to collaborators on Jul 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    outdated

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions