New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

this in es6 object #814

Closed
gko opened this Issue Feb 17, 2015 · 7 comments

Comments

Projects
None yet
2 participants
@gko

gko commented Feb 17, 2015

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

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

@kittens

This comment has been minimized.

Show comment
Hide comment
@kittens

kittens Feb 17, 2015

Member

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

Member

kittens commented Feb 17, 2015

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

@kittens kittens closed this Feb 17, 2015

@kittens kittens added the duplicate label Feb 17, 2015

@kittens

This comment has been minimized.

Show comment
Hide comment
@kittens

kittens Feb 17, 2015

Member

Duplicate of #733 and babel/babelify#37.

Member

kittens commented Feb 17, 2015

Duplicate of #733 and babel/babelify#37.

@gko

This comment has been minimized.

Show comment
Hide comment
@gko

gko Feb 17, 2015

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

gko commented Feb 17, 2015

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

@kittens

This comment has been minimized.

Show comment
Hide comment
@kittens

kittens Feb 17, 2015

Member

The outer this is undefined.

Member

kittens commented Feb 17, 2015

The outer this is undefined.

@gko

This comment has been minimized.

Show comment
Hide comment
@gko

gko Feb 17, 2015

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

gko commented Feb 17, 2015

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

@kittens

This comment has been minimized.

Show comment
Hide comment
@kittens

kittens Feb 17, 2015

Member

Nope. In ES6 modules the top this is undefined.

Member

kittens commented Feb 17, 2015

Nope. In ES6 modules the top this is undefined.

@kittens

This comment has been minimized.

Show comment
Hide comment
@kittens

kittens Feb 17, 2015

Member

See #562.

Member

kittens commented Feb 17, 2015

See #562.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment