diff --git a/backbone.js b/backbone.js index 022bf6b1c..86214fcbb 100644 --- a/backbone.js +++ b/backbone.js @@ -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; diff --git a/test/model.js b/test/model.js index c08e9a20d..2070bb250 100644 --- a/test/model.js +++ b/test/model.js @@ -322,5 +322,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); + }); });