Why is function window obj? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why is function window obj?

i put arrow function inside addeventlistener function, and this function output in console THIS (window obj). In function (check), THIS was missed and passed to function's addeventlistener and output in console window obj but not htmlDiv obj. Why? https://code.sololearn.com/WSlLl3MnBA6f/?ref=app https://code.sololearn.com/WSlLl3MnBA6f/?ref=app

8th Oct 2020, 11:05 AM
Maksym Gapachilo
Maksym Gapachilo - avatar
2 Answers
+ 1
Arrow functions by default have a different behavior when using "this". The easiest fix would be to use normal functions (Again, this is just the easy way, I believe there are ways to bind "this" to a certain object.
9th Oct 2020, 3:01 AM
Martín Stanicio
0
Arrow function,passed this to prev function THIS, but this doesn't work if the arrow or common function create not inside function, but beyond her
9th Oct 2020, 4:44 PM
Maksym Gapachilo
Maksym Gapachilo - avatar