An easily extendable base class
This library provides an easily extendable base class that comes with some very convenient built-in instance methods and class methods. It differs from other implementations of extend in that it makes adding class methods very easy and provides a parent() method that makes calling methods from parent classes easy and reliable.
npm install origin
First, require Origin
var Origin = require'origin';
Use the extend class method on Origin.Base or any subclass of Origin.Base to create a new subclass.
var MyClass = OriginBaseextend// This function will become the constructor for your// new class// You can define the variables and methods that will be// present in each instance of your new class. Sublasses// of this class, created using MyClass.extend() will// persist these these properties unless they are overridden// by the subclass.properties :someVariable : "some value"// All instances have a cls method that will return// the class of the object.if arg1 instanceof thiscls// All objects that extend from Origin have a parent// method that allows you to call a method of any parent// class.thisparentParentClasssomeOtherFunctionarg1;classProperties :// You can easily attach class methods to any class you define.// Subclasses of this class, created with MyClass.extend(), will// persist these class methods unless they're overriden by a// subclass.;var myClassInstance = arg1 arg2;
var Subclass = Classextendproperties :classMethods :;
Exactly as Origin.extend() allows you to create a subclass of Origin, calling the extend class method on any subclass of Origin creates a subclass of that class. extend() takes a single dictionary that may contain an "initializer" function (the constructor for the resulting class), a "properties" object containing values or methods to attach to instances of your new class, and a "classProperties" object that contains any class methods that you'd like attached to your new class.
Returns true if the class you're calling inheritsFrom on is a subclass of the class that you pass in as an argument. Returns false otherwise.
var ParentClass = Classsuperclass;
Returns the parent class.
var MyClass = ParentClassextendproperties :thisparentParentClassmyFunctionarg1;;
Takes a superclass of the current object's class and returns a dictionary with methods corresponding to the methods available in that superclass. Calling one of those methods behaves as expected and maintains the correct context of 'this'.
var MyClass = ParentClassextendproperties :if arg1clsinheritsFromParentClassreturn true;elsereturn false;;
Returns the class of the current object.
Released under the MIT license. See file called LICENSE for more details.