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

136
Views
¿Por qué el valor 'este' es diferente en Javascript?
var obj = { a: 2, } var a = 3; const func = () => { console.log(this.a); } function test() { setTimeout(func, 100); } function test2() { setTimeout(() => { console.log(this.a); }, 100); } test.call(obj); //3 test2.call(obj); //2

Parecía que test y test2 son iguales, pero el resultado devuelto es diferente, ¿cuál es el problema con 'esto'?

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

con la función de arrow de test , this se referirá al objeto de la window , y como var a = 3 , la a se asignará como una propiedad a la window , será como

 window.a

Pero en test2 this se referirá al objeto obj .

about 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!