在事件执行后仍然绑定了骨干事件,在触发器
之后没有执行object.offpfb代码摘要
var object = _.extend({}, Backbone.Events);
object.off('app:test:load', function() {
console.log("========my foot=======");
}, this);
object.on('app:test:load', function () {
//fn calls
});
object.trigger('app:test:load');
欢迎所有的想法,提前谢谢。
答案 0 :(得分:2)
此代码存在多个问题:
可能会对这个问题有所了解的工作实例:
// create object which support events
var object = _.extend({}, Backbone.Events);
// define function as non-anonymous
var doAction = function () {
console.log("========my foot=======");
};
// function has to be registered first (cannot remove something that is not there)
object.on('app:test:load', doAction);
// register another function to illustarate removal of anonymous functions
object.on('app:test:load', function(){
console.log("from anonymous");
});
// will invoke both functions
object.trigger('app:test:load');
// example 1: only remove this particular function for this particular trugger
object.off('app:test:load', doAction);
// will invoke only anonymous, since first one was removed
object.trigger('app:test:load');
// example 2: only remove ALL registered functions for this trigger
object.off('app:test:load');
// will not write anything
object.trigger('app:test:load');
答案 1 :(得分:0)
我认为你在谈论僵尸对象,这在Derick Bailey中有解释 - 帖子
这意味着对代码的某些部分有引用,而off方法不会删除它。