Consider the following example: https://deck.net/69d832ef112571a2c8c21564707a7b88
The behavior to expect ist that the console outputs "handler 1" and then "handler 2".
The actual behavior is: The console only outputs "handler 1", because handler 2 gets skipped. This is due to the fact that handler 1 removes itself from the listener collection, which causes the caller loop in Bridge to skip the other listener. Perhaps you need to reverse your for-loop so that it counts from (list.length-1) down to 0:
The behavior to expect ist that the console outputs "handler 1" and then "handler 2".
The actual behavior is: The console only outputs "handler 1", because handler 2 gets skipped. This is due to the fact that handler 1 removes itself from the listener collection, which causes the caller loop in Bridge to skip the other listener. Perhaps you need to reverse your for-loop so that it counts from (list.length-1) down to 0:
$build: function (handlers) {
var fn = function () {
var list = fn.$invocationList,
result = null,
i,
handler;
for (i = 0; i < list.length; i++) {
handler = list[i];
result = handler.apply(null, arguments);
}
return result;
};
fn.$invocationList = handlers ? Array.prototype.slice.call(handlers, 0) : [];
if (fn.$invocationList.length === 0) {
return null;
}
return fn;
}
Comment