Permalink
Browse files

Merge branch 'master' of github.com:documentcloud/backbone

  • Loading branch information...
2 parents 2eabf04 + cb988aa commit 804bb551cbf3deaadd067063803a5a1f4fb89ce4 @jashkenas committed Oct 1, 2012
Showing with 18 additions and 7 deletions.
  1. +7 −7 backbone.js
  2. +11 −0 test/model.js
View
@@ -183,19 +183,19 @@
// is automatically generated and assigned for you.
var Model = Backbone.Model = function(attributes, options) {
var defaults;
- attributes || (attributes = {});
+ var attrs = attributes || {};
if (options && options.collection) this.collection = options.collection;
if (options && options.parse) attributes = this.parse(attributes);
if (defaults = _.result(this, 'defaults')) {
- attributes = _.extend({}, defaults, attributes);
+ attrs = _.extend({}, defaults, attrs);
}
this.attributes = {};
this._escapedAttributes = {};
this.cid = _.uniqueId('c');
this.changed = {};
this._silent = {};
this._pending = {};
- this.set(attributes, {silent: true});
+ this.set(attrs, {silent: true});
// Reset change tracking.
this.changed = {};
this._silent = {};
@@ -1435,19 +1435,19 @@
child = function(){ parent.apply(this, arguments); };
}
+ // Add static properties to the constructor function, if supplied.
+ _.extend(child, parent, staticProps);
+
// Set the prototype chain to inherit from `parent`, without calling
// `parent`'s constructor function.
- function Surrogate(){ this.constructor = child; };
+ var Surrogate = function(){ this.constructor = child; };
Surrogate.prototype = parent.prototype;
child.prototype = new Surrogate;
// Add prototype properties (instance properties) to the subclass,
// if supplied.
if (protoProps) _.extend(child.prototype, protoProps);
- // Add static properties to the constructor function, if supplied.
- _.extend(child, parent, staticProps);
-
// Set a convenience property in case the parent's prototype is needed
// later.
child.__super__ = parent.prototype;
View
@@ -816,4 +816,15 @@ $(document).ready(function() {
strictEqual(model.save(), false);
});
+ test("#1545 - `undefined` can be passed to a model constructor without coersion", function() {
+ var Model = Backbone.Model.extend({
+ defaults: { one: 1 },
+ initialize : function(attrs, opts) {
+ equal(attrs, undefined);
+ }
+ });
+ var emptyattrs = new Model();
+ var undefinedattrs = new Model(undefined);
+ });
+
});

0 comments on commit 804bb55

Please sign in to comment.