BlitzmachineB
Reactiflux6mo ago
9 replies
Blitzmachine

.blitzmachine – 17-08 Sep 9

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?
Was this page helpful?