I have a problem to understand this in Arrow functions.
I read a lot of answers for example: Methods in ES6 objects: using arrow functions and explantation in this description Link github and everyone say that this should bind to Window , but when I check these examples I see undefined, If any of you, know why?
var foo = {
bar: () => console.log(this) // lexical this is window or something else
}
foo.bar()
I am using babel to transpile the code:
var foo = {
bar: function bar() {
return console.log(undefined);
}
}
babel versions are:
- "babel-core": "^6.21.0",
- "babel-loader": "^6.2.10",
- "babel-preset-es2015": "^6.18.0",
- "babel-preset-stage-2": "^6.18.0",
but lexical this is not Window only undefined, Why ?