-
Notifications
You must be signed in to change notification settings - Fork 1
inheritance
When you wish to make a subclass of an existing sudo Class Object you must do two things:
-
Create a "constructor" function for your new subclass
-
Use the Object.create method to inherit the prototype of the Class Object you want
// the 'constructor' var Foo = function(el, data) { // works because sudo.View used the 'sudo.inherit' method this.construct(el, data); }; // clone the View Class Object's prototype Foo.prototype = Object.create(sudo.View.prototype); // add your code Foo.prototype.bar = function(baz) {...};
There are two noteworthy things in the above example. One, we can call to the "super constructor" of our Foo View subclass via the this.construct()
method. Two, in order to inherit the methods on the sudo.View
prototype we must "clone" it with the Object.create method.
If you were to subclass the Foo Class Object above the same way it suclassed sudo.View
with a Bar class, that Bar class would not inherit the constructor Foo. This is a point of great confusion, but it's easy to understand:
** A "Constructor" function is not on its own prototype**