Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #26 from olivernn/clone-events-array

Slice the events array before looping through it
  • Loading branch information...
commit 944c2da9570f4946d612acb72449753ad4a80cd6 2 parents 2a38718 + d02dc67
@benpickles authored
Showing with 19 additions and 1 deletion.
  1. +1 −1  src/event_emitter.js
  2. +18 −0 test/tests/event_emitter_test.js
View
2  src/event_emitter.js
@@ -33,7 +33,7 @@
EventEmitter.prototype.emit = function(name) {
var args = Array.prototype.slice.call(arguments, 1)
- var events = prepareEvent.call(this, name)
+ var events = prepareEvent.call(this, name).slice()
for (var i = 0, length = events.length; i < length; i++) {
var callback = events[i].callback
View
18 test/tests/event_emitter_test.js
@@ -50,3 +50,21 @@ test("unbinding by callback and scope", 1, function() {
ee.emit("a")
})
+
+test("emitting events with callbacks that unbind events", function () {
+ var ee = new Model.EventEmitter,
+ eventName = 'test',
+ callbackCalled = false
+
+ var handler = function () {
+ ee.off(eventName, arguments.callee)
+ }
+
+ ee.on('test', handler)
+ ee.on('test', function () { callbackCalled = true })
+
+ ee.emit('test')
+
+ ok(callbackCalled)
+
+})
Please sign in to comment.
Something went wrong with that request. Please try again.