-
-
Notifications
You must be signed in to change notification settings - Fork 30.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Why this pointing to global context is giving undefined, even when global variable is defined ? #1106
Comments
I guess, when you call "data.getStatus.call(this)", getStatus method setting the value of "this" to global object. But inside getStatus method, "this.status" trying to access global object property , not the status property inside setTimeout. If we change getStatus function to arrow function, issue will get resolved.
|
@ManjulaP1012 actually the expected output should be "online" as |
the reason it was returning
|
It should work, you can see the working example here |
this is my program
why
console.log(data.getStatus.call(this))
is returningundefined
?The text was updated successfully, but these errors were encountered: