@wise-community/drawing-tool
Version:
HTML5 Drawing Tool
33 lines (32 loc) • 831 B
JavaScript
/**
* Inherit the prototype methods from one constructor into another.
*
* Usage:
* function ParentClass(a, b) { }
* ParentClass.prototype.foo = function(a) { }
*
* function ChildClass(a, b, c) {
* ParentClass.call(this, a, b);
* }
*
* inherit(ChildClass, ParentClass);
*
* var child = new ChildClass('a', 'b', 'see');
* child.foo(); // works
*
* In addition, a superclass' implementation of a method can be invoked
* as follows:
*
* ChildClass.prototype.foo = function(a) {
* ChildClass.super.foo.call(this, a);
* // other code
* };
*
* @param {Function} Child Child class.
* @param {Function} Parent Parent class.
*/
module.exports = function inherit(Child, Parent) {
Child.prototype = Object.create(Parent.prototype);
Child.prototype.constructor = Child;
Child.super = Parent.prototype;
};