Answer the question
In order to leave comments, you need to log in
Why do object and class have different this?
Why does this refer to the class in the first case, and to Windows in the second?
And how is this looked up when calling functions?
class Test {
static t = this
}
Test.t
const obj = { t: this }
obj.t
Answer the question
In order to leave comments, you need to log in
Try creating a function on the object that will return this:
const obj = {
GetThis(){
return this;
}
}
console.log(obj.GetThis());
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question