this in es6 object #814

Closed
gko opened this Issue Feb 17, 2015 · 7 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
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
Member
kittens commented Feb 17, 2015

Duplicate of #733 and babel/babelify#37.

@gko
gko commented Feb 17, 2015

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

@kittens
Member
kittens commented Feb 17, 2015

The outer this is undefined.

@gko
gko commented Feb 17, 2015

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

@kittens
Member
kittens commented Feb 17, 2015

Nope. In ES6 modules the top this is undefined.

@kittens
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