I found an unexpected value of this keyword in the following example :
let x = {
z : 10 ,
get func1() {
return function(v) {
console.log(this === v);
}
}
}
x.func1(x)
The value of this keyword is the object x as if it's executed from that object, I expect only the get function that has this keyword equals to the calling object x
this example shows us the difference
let x = {
func2() {
return function(v) {
console.log(this === v);
}
}
}
x.func2()(x);
In both examples func1 which is the getter function, and func2 which is a method of the object, are executed from the object x, and the returned function is then executed. So why this value in the first example not equals to the global object instead of the object x.