小编GGG*_*205的帖子

Angular 2 document.removeEventListener在类中不起作用

当动作结束时,我无法删除事件.我点击初始化事件:

<span class="leftTopPoint" (click)="initResize($event)"></span>

export class SectionComponent {
    ...

    initResize(e): void {
        this.mouseX = e.clientX;
        this.mouseY = e.clientY;

        document.addEventListener('mousemove', this.onResize.bind(this), false);
        document.addEventListener('mouseup', this.stopResize.bind(this), false);
    }
}
Run Code Online (Sandbox Code Playgroud)

我使用.bind(this)然后指针这没关系,但是当我调用stopResize()的方法时,removeEventListener不起作用.方法onResize()仍然有效.

export class SectionComponent { ...
    stopResize(e): void {
        document.removeEventListener('mousemove', this.onResize, false);
        document.removeEventListener('mouseup', this.stopResize, false);
    }
}
Run Code Online (Sandbox Code Playgroud)

javascript events angular

3
推荐指数
2
解决办法
4175
查看次数

Solidity:为什么使用初始化函数而不是构造函数?

我正在做审计智能合约,有人更喜欢使用这样的初始化函数:

 bool private isInit=false;
 string private hello;
 
 function init(string _hello) public onlyOwner {
   hello = _hello;
   isInit = true;
 } 

 function doSomething() public {
   require(isInit, "Wait for initialize");
   ...doSomething
 }
Run Code Online (Sandbox Code Playgroud)

你能解释一下为什么没有使用构造函数吗?

architecture state ethereum solidity smartcontracts

3
推荐指数
1
解决办法
4388
查看次数