Make one class (constructor function) inherited from another.
Based on extend method from YUI library.
component install gamtiq/extend
jam install extend
jspm install extend
bower install extend
Use dist/extend.js or dist/extend.min.js (minified version).
var extend = require("extend");
...var extend = require("gamtiq/extend");
...var extend = require("./path/to/dist/extend.js");
...require(["extend"], function(extend) {
...
});System.import("extend").then(function(extend) {
...
});define(["path/to/dist/extend.js"], function(extend) {
...
});<!-- Use bower_components/extend/dist/extend.js if the library was installed via Bower -->
<script type="text/javascript" src="path/to/dist/extend.js"></script>
<script type="text/javascript">
// extend is available via extend field of window object
...
</script>var SuperClass = function(a, b) {
...
};
SuperClass.prototype.method1 = function(c, d, e) {
...
};
...
var SubClass = function(a, b) {
...
SubClass.superconstructor.call(this, a, b);
// or
// SubClass.superconstructor.apply(this, arguments);
...
};
extend(SubClass, SuperClass);
...
SubClass.prototype.method1 = function(c, d, e) {
...
SubClass.superclass.method1.call(this, c, d, e);
// or
// SubClass.superclass.method1.apply(this, arguments);
...
};
...
if (extend.isSubclass(SubClass, SuperClass)) {
...
}See test/extend.js for additional examples.
Replace value of prototype field of SubClass by another object that inherits from prototype of ParentClass.
Returns SubClass.
Test whether SubClass is inherited from ParentClass.
MIT