所以我正在阅读Backbone源代码,我正在查看on函数 -
on: function(name, callback, context) {
if (!(eventsApi(this, 'on', name, [callback, context]) && callback)) return this;
this._events || (this._events = {});
var list = this._events[name] || (this._events[name] = []);
list.push({callback: callback, context: context, ctx: context || this});
return this;
},
我没有看到'all'事件有任何特殊情况 - 这是在哪里实现的?
答案 0 :(得分:0)
当您致电on('all' ,...)
时,您的回调会被推送到this.events.all
数组:
var list = this._events[name] || (this._events[name] = []);//-> this._events.all = []
然后当trigger
被解雇时,它会检查:
var allEvents = this._events.all