-1

因此,我正在阅读 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;
},

我没有看到“所有”事件的任何特殊情况 - 这是在哪里实现的?

4

1 回答 1

0

当你调用on('all' ,...)你的回调被推入this.events.all数组:

var list = this._events[name] || (this._events[name] = []);//-> this._events.all = []

然后当它trigger被触发时,它会检查:

var allEvents = this._events.all
于 2013-02-28T10:28:52.427 回答