You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Because .trigger() is iterating over the array of callbacks when a callback unbinds itself .splice() modifies the array and the it's length decreases by one so the next callback in line is skipped.
In the following example we unbind function B in it's own callback. We would expect "ABC" to be output but instead we only get "AB".
vare=newMicroEvent();e.bind('change',functionA(){console.log('A');});e.bind('change',functionB(){console.log('B');e.unbind('change',B);});e.bind('change',functionC(){console.log('C');});e.trigger('change');//=> Expect A B C, but C is not called.
There are at least two solutions, clone the array in either the .trigger() or .unbind() methods. [].slice() will do this.
The text was updated successfully, but these errors were encountered:
Because
.trigger()
is iterating over the array of callbacks when a callback unbinds itself.splice()
modifies the array and the it's length decreases by one so the next callback in line is skipped.In the following example we unbind function B in it's own callback. We would expect "ABC" to be output but instead we only get "AB".
There are at least two solutions, clone the array in either the
.trigger()
or.unbind()
methods.[].slice()
will do this.The text was updated successfully, but these errors were encountered: