[Pkg-javascript-commits] [backbone] 154/173: Fix 1.3.1 regression with once and no context
Jonas Smedegaard
dr at jones.dk
Wed Aug 31 07:44:15 UTC 2016
This is an automated email from the git hooks/post-receive script.
js pushed a commit to branch master
in repository backbone.
commit 1db79ddd33f65e4ca93beb3174496cf148baebe5
Author: Graeme Yeates <yeatesgraeme at gmail.com>
Date: Mon Mar 7 12:35:37 2016 -0500
Fix 1.3.1 regression with once and no context
---
backbone.js | 1 +
test/events.js | 12 ++++++++++++
2 files changed, 13 insertions(+)
diff --git a/backbone.js b/backbone.js
index d0cad3e..ecfc253 100644
--- a/backbone.js
+++ b/backbone.js
@@ -308,6 +308,7 @@
Events.once = function(name, callback, context) {
// Map the event into a `{event: once}` object.
var events = eventsApi(onceMap, {}, name, callback, _.bind(this.off, this));
+ if (typeof name === 'string' && context == null) callback = void 0;
return this.on(events, callback, context);
};
diff --git a/test/events.js b/test/events.js
index bebcb0e..544b39a 100644
--- a/test/events.js
+++ b/test/events.js
@@ -417,6 +417,18 @@
assert.equal(obj.counterB, 1, 'counterB should have only been incremented once.');
});
+ QUnit.test('bind a callback with a default context when none supplied', function(assert) {
+ assert.expect(1);
+ var obj = _.extend({
+ assertTrue: function() {
+ assert.equal(this, obj, '`this` was bound to the callback');
+ }
+ }, Backbone.Events);
+
+ obj.once('event', obj.assertTrue);
+ obj.trigger('event');
+ });
+
QUnit.test('bind a callback with a supplied context', function(assert) {
assert.expect(1);
var TestClass = function() {
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/backbone.git
More information about the Pkg-javascript-commits
mailing list