From f5a67ec60e3aba04b5fb901e011a8f2528b6ec6c Mon Sep 17 00:00:00 2001 From: Viacheslav Lotsmanov Date: Thu, 13 Oct 2016 01:40:00 +0500 Subject: [PATCH 1/2] Add comment about combined _.defaults and _.extend Squashed from the original commits in #4088. --- backbone.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/backbone.js b/backbone.js index 251d6c5fa..110b28fbd 100644 --- a/backbone.js +++ b/backbone.js @@ -404,7 +404,13 @@ if (options.collection) this.collection = options.collection; if (options.parse) attrs = this.parse(attrs, options) || {}; var defaults = _.result(this, 'defaults'); + + // Additional `_.defaults()` wrap after `_.extend()` makes sense + // when `attrs` has a property explicitly set to `undefined`. + // Also it helps to avoid conflicts with Object.prototype properties. + // Issue #3842 attrs = _.defaults(_.extend({}, defaults, attrs), defaults); + this.set(attrs, options); this.changed = {}; this.initialize.apply(this, arguments); From 790682c2fd7e1ea5893d6594430701064df57104 Mon Sep 17 00:00:00 2001 From: Julian Gonggrijp Date: Wed, 19 Jul 2023 22:45:50 +0200 Subject: [PATCH 2/2] Change the comment (#4088) --- backbone.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/backbone.js b/backbone.js index 110b28fbd..bc4f18f9a 100644 --- a/backbone.js +++ b/backbone.js @@ -405,10 +405,8 @@ if (options.parse) attrs = this.parse(attrs, options) || {}; var defaults = _.result(this, 'defaults'); - // Additional `_.defaults()` wrap after `_.extend()` makes sense - // when `attrs` has a property explicitly set to `undefined`. - // Also it helps to avoid conflicts with Object.prototype properties. - // Issue #3842 + // Just _.defaults would work fine, but the additional _.extends + // is in there for historical reasons. See #3843. attrs = _.defaults(_.extend({}, defaults, attrs), defaults); this.set(attrs, options);