要移除事件必须在注册事件时传入target??

this.node.on( ‘bulletAttackEnemy’,()=>{})
然后使用 this.node.targetOff( this.node )好像没有移除事件,然后改成 this.node.targetOff( this )也没有,
之后注册事件的时候写成 this.node.on( ‘bulletAttackEnemy’,()=>{}, this), this.node.targetOff( this )就移除了事件。
因为是节点进行事件监听,然后又出现了target,一般会直接默认这个target不就应该是节点吗?结果还要绑定一个target,target没有设定默认值吗?

return this._EventTargetOn(type, callback, target, useCapture);

这是on return出来的接口。可以看到主要是this这个环境变量在接收和处理事件,而不是this.node。

targetOff(target) {
        this._EventTargetTargetOff(target);

        this._checkTouchListeners();
        this._checkMouseListeners();
},

然后你再看一下targetOff的代码你就懂了。

1赞

可以帮忙看下这个问题吗?
https://forum.cocos.com/t/targetoff/81473?u=306815785