jashkenas / backbone

Give your JS App some Backbone with Models, Views, Collections, and Events
http://backbonejs.org
MIT License
28.09k stars 5.39k forks source link

There is a reference error in the trigger event #4211

Closed ys-yancy closed 5 years ago

ys-yancy commented 5 years ago

When I am off event, the events in the trigger function can't be synchronized, because the var events = this._events[name] statement in the trigger function is wrong, this._events[name] = retain = in the off function. The var events = this._events[name] in the [] statement and the trigger function are two different reference addresses.

The trigger function should be changed to:

trigger: function(name) {
      if (!this._events) return this;
      var args = slice.call(arguments, 1);
      if (!eventsApi(this, 'trigger', name, args)) return this;

      //var events = this._events[name];

      var allEvents = this._events.all;
      if (this._events[name]) triggerEvents(this._events[name], args);
      if (allEvents) triggerEvents(allEvents, arguments);
      return this;
    },
paulfalgout commented 5 years ago

perhaps a codepen or jsfiddle reproducing the error would help

taburetkin commented 5 years ago

deleted: sorry, its definitelly different thing