[Pkg-javascript-commits] [backbone] 48/211: Fixing a small bug in model inheritance: Class properties need to be inherited (along with the instance properties). See test.

Jonas Smedegaard js at moszumanska.debian.org
Sat May 3 17:00:00 UTC 2014


This is an automated email from the git hooks/post-receive script.

js pushed a commit to tag 0.5.0
in repository backbone.

commit 440d1415fb8f9152af8c19bcec3b2433979a1624
Author: Samuel Clay <samuel at ofbrooklyn.com>
Date:   Wed Jan 5 16:35:05 2011 -0500

    Fixing a small bug in model inheritance: Class properties need to be inherited (along with the instance properties). See test.
---
 backbone.js   |  3 +++
 test/model.js | 24 ++++++++++++++++++++++++
 2 files changed, 27 insertions(+)

diff --git a/backbone.js b/backbone.js
index 356405b..d3e94b0 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 5a313dc..2d887f3 100644
--- a/test/model.js
+++ b/test/model.js
@@ -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);
+  });
 
 });

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/backbone.git



More information about the Pkg-javascript-commits mailing list