在backbone.js源中实现的all事件在哪里?

时间:2013-02-28 10:26:24

标签: javascript backbone.js

所以我正在阅读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'事件有任何特殊情况 - 这是在哪里实现的?

1 个答案:

答案 0 :(得分:0)

当您致电on('all' ,...)时,您的回调会被推送到this.events.all数组:

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

然后当trigger被解雇时,它会检查:

var allEvents = this._events.all