-
-
Save sleepynate/1715403 to your computer and use it in GitHub Desktop.
| it("derps when using a space in an event name", function() { | |
| var callback = jasmine.createSpy('-Custom Event Callback-'); | |
| obj.bind('all', callback); | |
| obj.trigger("foo bar"); | |
| expect(callback.callCount).toBe(1); | |
| expect(callback.mostRecentCall.args[0]).toBe('foo bar'); | |
| }); |
Ah, so binding works with space-separated events but triggering is still a singular operation. That makes sense because arguments from .trigger are passed along to the function that was bound. Triggering two events at once doesn't seem like it would be something that would be frequently done and even if you wanted to you would have no way to determine which arguments were passed to the callback. (By convention backbone passes the model instance AND the changed attribute[singular] to the callback).
In the case of
person.bind("change:name change:location", callback);the callback will fire two times and the arguments will contain the model and changed value of each field
ie:
callback(model, name);
callback(model, location);
Yea check out the expectation in larry's project: https://github.com/larrymyers/backbone-koans/blob/master/js/koans/aboutEvents.js#L66
EXCEPT that on line 5, you used to be able to name a single event "foo bar"