extend-light - npm
extend-light defines class in JavaScript.
This is simple module providing a simple Class function to
simplify class definition in JavaScript.
Easy to use, easy to inherit/extend.
no difficult keywords,
no prototype
, no __proto__
,
no Object.defineProperty
, no Object.setPrototypeOf
, etc ...
needs constructor
only.
Supports Google Chrome, Mozilla Firefox, Microsoft ie11/10/9/8/7/6 and Node.js/io.js.
INSTALL:
$ npm install extend-light
or
http://lightspeedworks.github.io/extend-light/extend-light.js
USAGE:
var extend = ;
method: [BaseClass].extend([proto], [staticProps])
Define new class (constructor function) that inherited from Base Class.
Format
var YourClass = ;var YourSubClass = YourClass;
Parameters
- BaseClass: Base class or Super class for inherits
- proto: the prototype object for your class, optional
- constructor or new: constructor function, optional
- any methods: any method or member function, optional
- statics: the object for class or static properties, optional
- any methods: any method or member function, optional
- staticProps: the object for class or static properties, optional
- any methods: any static method or class function, optional
You have to omit staticProps also, if you omit proto.
You have to specify proto or {}
, if you want to specify staticProps.
Returns
The newly defined class (constructor function). (Your class is subclass of BaseClass)
Details
A simple and quick sample:
var extend = ; var MyClass = ; var myObj = 5;myObjvalue++; // 5 -> 6myObj;myObjvalue++; // 6 -> 7
EXAMPLES:
// Animal // extendvar extend = ; // SimpleClassvar SimpleClass = ;var s1 = ; // Animalvar Animal = ;var a1 = 'Annie';a1; // -> My name is AnnieAnimal; // -> Animal class method // Bearvar Bear = Animal;var b1 = ; // new lessb1; // -> My name is Pooh var Cat = Animal;var c1 = 'Kitty';c1; // -> My name is Kitty var Dog = Animal; // -> Dog initvar d1 = 'Hachi';d1; // -> My name is HachiDog; // -> Animal class method, Dog class methodDog; // -> Animal class method
SEE ALSO:
base-class-extend - npm
get-constructors - npm
LICENSE:
MIT