documentcloud/backbone — pull request #1545 by etlovett (2012-08-13 05:30:46+00:00)
Title: Ensure defaults are passed to Backbone.Model.initialize.

Without this fix, if you create a model via `new MyModel()`, then the defaults specified in `MyModel` aren't passed to the `initialize` method. This is perfectly illustrated by the test I've modified ("Model: defaults always extend attrs (#459)"): without my fix, it's necessary to use `this.attributes` inside `initialize` rather than `attrs` to get the assertion to pass for the `new Defaulted()` case. This therefore makes the `initialize` API much more consistent.

Two other comments about this fix:
1. I would have used `Array.prototype.slice` and `concat` to generate `args`, but I noticed that this was explicitly avoided in `Backbone.Events.trigger`, so I copied that pattern even though it's more code.
2. I did not also include this fix in `Backbone.Collection`, `Backbone.View`, or `Backbone.Router`, because they do not appear to modify their arguments before calling `initialize`. However, it might be a good idea to also include this fix in those constructors to be more future-proof. I can add that to this pull request if you would like.

FYI, this bug was introduced in commit 4316b04ffa75257e9eec9fe46b3c48535b659936.