From c87833877f4b14484c951cb688765f992f36f6eb Mon Sep 17 00:00:00 2001 From: Julian Gonggrijp Date: Thu, 20 Jul 2023 22:39:16 +0200 Subject: [PATCH] Apply fix suggested by @paulfalgout (#4262) See https://github.com/jashkenas/backbone/pull/4265#discussion_r1269749470 --- backbone.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/backbone.js b/backbone.js index aaa9f759..f1c98d08 100644 --- a/backbone.js +++ b/backbone.js @@ -1082,7 +1082,7 @@ var forwardPristineError; options.success = function(m, resp, callbackOpts) { if (wait) { - model.off('error', forwardPristineError); + m.off('error', forwardPristineError, this); collection.add(m, callbackOpts); } if (success) success.call(callbackOpts.context, m, resp, callbackOpts); @@ -1096,8 +1096,11 @@ // causes the collection to listen, and then invoke the callback // that triggers the event.) if (wait) { - forwardPristineError = _.bind(this._onModelEvent, this, 'error'); - model.once('error', forwardPristineError); + forwardPristineError = function(mod, col, opt) { + if (this.has(mod)) return; + this._onModelEvent('error', mod, col, opt); + }; + model.once('error', forwardPristineError, this); } model.save(null, options); return model;