Skip to content

Commit

Permalink
Merge branch 'master' of github.com:documentcloud/backbone
Browse files Browse the repository at this point in the history
  • Loading branch information
jashkenas committed Jan 11, 2011
2 parents 289d4e0 + 440d141 commit 39cabb8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
3 changes: 3 additions & 0 deletions backbone.js
Expand Up @@ -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;
Expand Down
24 changes: 24 additions & 0 deletions test/model.js
Expand Up @@ -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);
});

});

0 comments on commit 39cabb8

Please sign in to comment.