Skip to content

this in es6 object #814

Closed
Closed

Description

@gko
var A = {
    test: () => {this}
};

why is this in code above translated to undefined instead of pointing to object itself?

Activity

  1. sebmck commented on Feb 17, 2015

    @sebmck
    Contributor

    Because you're using a fat arrow function and it infers to the outer this.

  2. sebmck commented on Feb 17, 2015

    @sebmck
    Contributor

    Duplicate of #733 and babel/babelify#37.

  3. gko commented on Feb 17, 2015

    @gko
    Author

    I know about arrow functions, but wouldn't the «outer this» be object in this case?

  4. sebmck commented on Feb 17, 2015

    @sebmck
    Contributor

    The outer this is undefined.

  5. gko commented on Feb 17, 2015

    @gko
    Author

    It depends on where do you execute function. I.e. outer this can be window object.

  6. sebmck commented on Feb 17, 2015

    @sebmck
    Contributor

    Nope. In ES6 modules the top this is undefined.

  7. sebmck commented on Feb 17, 2015

    @sebmck
    Contributor

    See #562.

  8. added
    outdated
    on Jan 18, 2019
  9. locked as resolved and limited conversation to collaborators on Jan 18, 2019
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