Skip to content

Commit

Permalink
Ensure that behavior events are bound to the behavior.
Browse files Browse the repository at this point in the history
  • Loading branch information
TheCloudlessSky committed Mar 25, 2014
1 parent 1492c80 commit b96072d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docs/marionette.behavior.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ var CloseWarn = Marionette.Behavior.extend({
"message": "you are closing!"
},

// behaviors have events that are bound to the views DOM
// Behaviors have events that are bound to the behavior instance
events: {
"click .close": "warnBeforeClose"
},
Expand Down
6 changes: 3 additions & 3 deletions spec/javascripts/behaviors.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,16 +164,16 @@ describe("Behaviors", function(){
v.render();
v.$el.click();

expect(spy).toHaveBeenCalled();
expect(spy2).toHaveBeenCalled();
expect(spy).toHaveBeenCalledOn(sinon.match.instanceOf(Marionette.Behavior));
expect(spy2).toHaveBeenCalledOn(sinon.match.instanceOf(Marionette.Behavior));
});

it("should call the behaviors event when event handler is a string", function() {
v = new V();
v.render();
v.$el.click();

expect(spy3).toHaveBeenCalled();
expect(spy3).toHaveBeenCalled(sinon.match.instanceOf(Marionette.Behavior));
});
});

Expand Down
2 changes: 1 addition & 1 deletion src/marionette.behaviors.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ Marionette.Behaviors = (function(Marionette, _) {
var eventKey = key + whitespace;
var handler = _.isFunction(behaviorEvents[key]) ? behaviorEvents[key] : b[behaviorEvents[key]];

_events[eventKey] = handler;
_events[eventKey] = _.bind(handler, b);
});

_behaviorsEvents = _.extend(_behaviorsEvents, _events);
Expand Down

0 comments on commit b96072d

Please sign in to comment.