Why arrow function this return window object and how I return obj ?
let obj = {
name:"Maxi",
fn :()=>this,
}
console.log(obj.fn())
Why arrow function this return window object and how I return obj ?
let obj = {
name:"Maxi",
fn :()=>this,
}
console.log(obj.fn())
Why arrow function this return window object
Because arrow functions capture the current value of this
at the time they are created.
how I return obj
Don't use an arrow function if you don't want to capture the current value of this
.
With arrow functions, this
is not bound to its own context.
Arrow functions do not create their own this
context, so this
has its original meaning from the enclosing context which is window
in your case.