backbone
backbone copied to clipboard
Add comment about combined _.defaults and _.extend
@jridgewell it's done. Is it okay that I made this revert commit? I mean if you do squash merge at the end it wont matter.
No, we can squash merge it. Still need the link to #3842. And someone else should look over the wording. @captbaritone? 😉
@jridgewell
Still need the link to #3842
Do you mean I should add #3842 to the commit message?
To the comment, not the commit message.
@jrburke how about now?
Rather than "makes sense" can you explain the behavior that it actually avoids?
@captbaritone I added line about it helps to avoid conflicts with Object.prototype properties.
I'm not familiar with this issue, and those who are reading this comment probably won't be either. In what way does it "make sense"? Does it preserve attributes which have been explicitly set to undefined? Does it overwrite them?
It has two steps.
- We have to create an object that contains all properties,
attrstaking precedence overdefaults. We clobber prototype inheritance here on purpose._.extend({}, defaults, attrs)
- Anything in Step 1 that is
undefinedshould be overridden with itsdefaultsvalue. Since we clobbered prototype inheritance, we know for certain that if something isundefined, it was set specifically toundefinedinattrs. (Or, if it was set indefaults, it will still beundefinedafter this step)_.defaults(_, defaults)
Superseded by #4267.