EventProxy來自于Backbone的事件模塊,Backbone的事件模塊是Model、View模塊的基礎功能,在前端有廣泛的使用。它在每個非all事件觸發時都會觸發一次all事件,相關代碼如下:
// Trigger an event, firing all bound callbacks. Callbacks are passed the
// same arguments as 'trigger' is, apart from the event name.
// Listening for '"all"' passes the true event name as the first argument
trigger : function(eventName) {var list, calls, ev, callback, args;var both = 2;if (!(calls = this._callbacks)) return this;while (both--) {ev = both ? eventName : 'all';if ( if = calls[ev]) {for ( var i = 0, l = list.length; i < l; i++) {if (!(callback = list[i])) {list.splice(i ,1); i--; l--;} else {args = both ? Array.prototype.slice.call(arguments, 1) : arguments;callback[0].apply(callback[1] || this, args);}}}}return this;}
詳情參考《深入淺出Node》P79