Blitzmachine
Blitzmachine5d ago

.blitzmachine – 17-08 Sep 9

class WhatEverYouCanImagine {
constructor() {
window.addEventListener("resize", this.onWindowResize);
}

private onWindowResize() {
this.resizeRendererToViewport();
this.resizeCameraAspect();
}
}
class WhatEverYouCanImagine {
constructor() {
window.addEventListener("resize", this.onWindowResize);
}

private onWindowResize() {
this.resizeRendererToViewport();
this.resizeCameraAspect();
}
}
What is exactly happening here actually? The EventListener loses reference to the class function .. inside a constructor. (I fixed it already - https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Function/bind) Is it because the constructor, while executing synchronous the code .. THIS refers in the time to the "shadow" class and loses it after constructor, cuz the instance of this class is now owned by a variable?
6 Replies
Blitzmachine
BlitzmachineOP5d ago
this.onWindowResize.bind(this)
this.onWindowResize.bind(this)
If I pass the real context with bind .. that is the only explanation?
Blitzmachine
BlitzmachineOP5d ago
No description
Blitzmachine
BlitzmachineOP5d ago
Like, I understand it, but also don't what happened .. if you understand. :doge:
Unknown User
Unknown User5d ago
Message Not Public
Sign In & Join Server To View
Blitzmachine
BlitzmachineOP5d ago
Seems like I missed it. Thank you much. Ye after thinking/reading .. it does makes sense. First this just refers to a func requiring the instance of the func provider .. but window has no access anymore to that reference. Ty
reactibot
reactibot2d ago
This thread hasn’t had any activity in 72 hours, so it’s now locked. Threads are closed automatically after 72 hours. If you have a followup question, you may want to reply to this thread so other members know they're related. https://discord.com/channels/102860784329052160/565213527673929729/1415021092061319179

Did you find this page helpful?