使用 detachPageDataLoaded 分离事件 [英] Detach event with detachPageDataLoaded
问题描述
我需要分离一个附加了以下代码的事件处理程序:
I need to detach an event handler that was attached with the following code:
var oNavController = this.getOwnerComponent().getAppComponent().getNavigationController();
this.extensionAPI.attachPageDataLoaded(this._executeTrampolin.bind(this, oNavController));
这是标准代码,我不想改变它.
因此,我尝试使用以下代码从扩展中删除此事件:
This is standard code, I don't want to change it.
So I'm trying to remove this event from an extension, with the following code:
var that = this.base.getView().getController();
var oNavController = that.getOwnerComponent().getAppComponent().getNavigationController();
that.extensionAPI.detachPageDataLoaded(that._executeTrampolin.bind(that, oNavController));
但是事件并没有被分离.
But the event is not getting detached.
推荐答案
const myFn = function() {};
const myFn2 = myFn.bind(thisArg);
myFn === myFn2; // returns: false
Function.prototype.bind
创建给定函数的新副本.
bind()
方法创建一个新函数 [...].
The
bind()
method creates a new function [...].
即分离事件处理程序时,您必须传递与在调用 this._executeTrampolin.bind(this, oNavController)
以附加处理程序时创建的完全相同的引用.
I.e. when detaching an event handler, you'll have to pass the exact same reference that was created when this._executeTrampolin.bind(this, oNavController)
was called once to attach the handler.
这篇关于使用 detachPageDataLoaded 分离事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!