JSKlass
Create classes with prototype object, static properties and mixins in JavaScript.
Getting Started
Install jsklass
module.
npm install jsklass
Include jsklass
and you can start work with it.
var Class = ; var Basic = Class;var Extended = Basic;
For example, you can create Animal class and extend it with Cat class.
var Animal = Class; var Cat = Animal; var justAnimal = ;justAnimal; // Animal var justCat = ;justCat; // Cat
API
API has simple method. When you create Class you call create
method of Class object.
If you want extends then call extend
in existing class.
var result = Class;result;
Examples
Working example you can find here.
Basic creating and extending
var BasicClass = Class; // BasicClass -> Objectvar ExtendedClass = BasicClass; // ExtendedClass -> BasicClass -> Objectvar MoreExtendedClass = ExtendedClass; // MoreExtendedClass -> ExtendedClass -> BasicClass -> Object
Creating classes with methods and attributes and extend them
var Class = ; var BasicClass = Class; var ExtendedClass = BasicClass; var MoreClass = BasicClass; var basic = ;console; // Basicconsole; // bar var extended = ;console; // ExtendedClassconsole; // undefinedconsole; // foo var more = ;console; // MoreClassconsole; // barconsole; // undefined
Creating classes with prototype and static methods
var BasicClass = Class; var ExtendedClass = BasicClass; console; // barconsole; // undefined console; // undefinedconsole; // foo
Creating classes with prototype, static and mixins
var Class = ; var EventEmitterMixin = { return "on"; } { return "off"; } { return "emit"; }; var OtherMixin = { return "Other"; }; var EventEmitter = Class;var EventEmitterAndOther = Class; var event = ;console; // onconsole; // offconsole; // emitconsole; // undefined var otherEvent = ;console; // onconsole; // offconsole; // emitconsole; // Other
License
The MIT License (MIT)
Copyright © 2015 Eugene Obrezkov
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.