Issue #1631: Fixed a bug on removeEventListener

Bugfix for issue #1631 where removeEventListener would throw when no event listeners are registered on the object.
This commit is contained in:
Daan Mortier 2013-04-29 11:53:16 +02:00
parent b31c9d50b8
commit 52498f1ef9
2 changed files with 9 additions and 0 deletions

View File

@ -126,6 +126,11 @@ describe('Events', function() {
expect(spy5.called).to.be(false);
});
it('can handle calls to #removeEventListener on objects with no registered event listeners', function () {
var obj = new Klass();
obj.removeEventListener('test');
});
// added due to context-sensitive removeListener optimization
it('fires multiple listeners with the same context with id', function () {
var obj = new Klass(),

View File

@ -63,6 +63,10 @@ L.Mixin.Events = {
removeEventListener: function (types, fn, context) { // ([String, Function, Object]) or (Object[, Object])
if (!this[eventsKey]) {
return this;
}
if (!types) {
return this.clearAllEventListeners();
}