mirror of
https://github.com/jashkenas/backbone.git
synced 2026-01-24 22:37:58 -05:00
Fixing a small bug in model inheritance: Class properties need to be inherited (along with the instance properties). See test.
This commit is contained in:
@@ -1004,6 +1004,9 @@
|
||||
child = function(){ return parent.apply(this, arguments); };
|
||||
}
|
||||
|
||||
// Inherit class (static) properties from parent.
|
||||
_.extend(child, parent);
|
||||
|
||||
// Set the prototype chain to inherit from `parent`, without calling
|
||||
// `parent`'s constructor function.
|
||||
ctor.prototype = parent.prototype;
|
||||
|
||||
@@ -320,5 +320,29 @@ $(document).ready(function() {
|
||||
equals(lastError, "Can't change admin status.");
|
||||
equals(boundError, undefined);
|
||||
});
|
||||
|
||||
test("Model: Inherit class properties", function() {
|
||||
var Parent = Backbone.Model.extend({
|
||||
instancePropSame: function() {},
|
||||
instancePropDiff: function() {}
|
||||
}, {
|
||||
classProp: function() {}
|
||||
});
|
||||
var Child = Parent.extend({
|
||||
instancePropDiff: function() {}
|
||||
});
|
||||
|
||||
var adult = new Parent;
|
||||
var kid = new Child;
|
||||
|
||||
equals(Child.classProp, Parent.classProp);
|
||||
notEqual(Child.classProp, undefined);
|
||||
|
||||
equals(kid.instancePropSame, adult.instancePropSame);
|
||||
notEqual(kid.instancePropSame, undefined);
|
||||
|
||||
notEqual(Child.prototype.instancePropDiff, Parent.prototype.instancePropDiff);
|
||||
notEqual(Child.prototype.instancePropDiff, undefined);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user