在 $.Callbacks() 中添加回调函数后,我想再次删除它:
var callbacks = $.Callbacks(),
foo = function() { console.log('Hello world') };
callbacks.add(foo);
callbacks.fire(); // logs 'Hello world'
callbacks.remove(foo);
callbacks.fire(); // nothing to trigger, removed perfectly
所以,这行得通,但现在我想添加一个匿名函数,如下所示:
callbacks.add(function(){ console.log('Hello anonymous world') });
callbacks.fire(); // logs 'Hello anonymous world'
看起来不错,但我不能再删除该功能:
callbacks.remove(function(){ console.log('Hello anonymous world') });
callbacks.remove();
callbacks.fire(); // still logs 'Hello anonymous world'
有没有办法克服这个问题?