Im quite new to javascript and sometimes I find it really hard to find what object a keyword 'this' refers to. Is there a code editor that is able to do that for me? Or any other advice that could help me :) Thanks!

  • Paste some code you're having trouble with. That will make it easier for people to help you. Dec 11, 2020 at 15:02
  • I think your are looking for alert(this.constructor.name);
    – R4444
    May 12, 2021 at 4:44

1 Answer 1


There's a great resource on W3Schools.

In summary:

It (this) has different values depending on where it is used:

  • In a method, this refers to the owner object.

  • Alone, this refers to the global object.

  • In a function, this refers to the global object.

  • In a function, in strict mode, this is undefined.

  • In an event, this refers to the element that received the event.

  • Methods like call(), and apply() can refer this to any object.

Answered with regard to getting function name here and with regard to getting function body here

  • Hi, thanks for your answer, but I know how it is used and what i'm looking for is an automatic way to reveal the corresponding object in a long and hard (obfuscated) code. Sorry if I wasn't clear.
    – Hukei
    Dec 12, 2020 at 18:37
  • It's evaluated at runtime, so looking at the code won't tell you anything. The code needs to be executed to understand what this means. Functions are mutable in javascript and can be defined (created) at runtime. You can have a function which creates functions through lambdas. To say ' I wan't to know what this means in a program ' is to say ' I want to know how the program is evaluated up to the point where this line of code is called.' The only way to know that is to evaluate the code. Dec 13, 2020 at 1:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.