Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

299
Views
Using this in functions: How does context work?
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

this points to the context. In event handlers, this is the element that received the event (the button, the div, the link...). If you call a function as if it were a method, this is the object. But the fact that the function is declared as a method does not ensure that it is called as such.

For example:

If you are in the global context (you are not inside any function), this is window

 console.log(this===window); function test() { console.log(this===window); if (this!==window) { console.log(this); } } test();

this is window

But if that function is an attribute of an object, then this becomes that object:

 function test() { console.log('Es window?:' + (this===window)); if (this!==window) { console.log('Es obj?:' + (this===obj)); } } console.log('Modo no estricto'); var obj={ prueba: 'hola' } test(); console.log('Como método'); obj.metodo=test; obj.metodo();


over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!