Make protoProps optional, when inheriting.

This commit is contained in:
Jeremy Ashkenas
2010-11-06 09:48:56 -04:00
parent 65c52763d3
commit 9a74dbc9c3
2 changed files with 6 additions and 4 deletions

View File

@@ -751,7 +751,7 @@
// The constructor function for the new subclass is either defined by you
// (the "constructor" property in your `extend` definition), or defaulted
// by us to simply call `super()`.
if (protoProps.hasOwnProperty('constructor')) {
if (protoProps && protoProps.hasOwnProperty('constructor')) {
child = protoProps.constructor;
} else {
child = function(){ return parent.apply(this, arguments); };
@@ -762,8 +762,9 @@
ctor.prototype = parent.prototype;
child.prototype = new ctor();
// Add prototype properties (instance properties) to the subclass.
_.extend(child.prototype, protoProps);
// 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.
if (staticProps) _.extend(child, staticProps);

View File

@@ -19,7 +19,8 @@ $(document).ready(function() {
length : 123
};
var doc = new Backbone.Model(attrs);
var proxy = Backbone.Model.extend();
var doc = new proxy(attrs);
var klass = Backbone.Collection.extend({
url : function() { return '/collection'; }