我无法在构造函数中更改全局布尔变量

时间:2017-04-24 16:55:54

标签: javascript constructor 3d three.js

我试图在我的构造函数中使用一个名为_mouseoverdistancebool的全局变量来注意鼠标何时位于distance中名为threejs的对象3D上。但价值永远不会改变。 这是影响变量的代码:

  constructor(targetMesh, controls, camera, container) {
    super();

    this._mouseoverdistancebool = false;

    this.addEventListeners();
  }

  addEventListeners() {
    this._distance.addEventListener('mouseleave', this.mouseleavedistance);
    this._distance.addEventListener('mouseenter', this.mouseenterdistance);

    this._container.addEventListener('mousewheel', this.onMove);
    this._container.addEventListener('DOMMouseScroll', this.onMove);

  }

  mouseenterdistance(evt) {
    console.log("Mouse over the object!!!");
    this._mouseoverdistancebool = true;
  }

  mouseleavedistance(evt) {
    console.log("Mouse leaves the object....");
    this._mouseoverdistancebool = false;
  }

  onMove(evt) {
    console.log(this._mouseoverdistancebool);
  }

所以我在调试中可以看到事件运行良好但布尔值总是为假。像这样:

>Mouse over the object!!!
>false
>Mouse leaves the object....
>false

我是javascript中构造函数的新手......我做错了什么?

0 个答案:

没有答案