Package Exports
- class-256.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (class-256.js) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
class-256.js
class-256.js is a less than 256 byte JavaScript classical inheritance pattern library (249 bytes minified or 391 bytes minified with UMD pattern).
Originally based on augment and extend.
Features
- OOP style declaration
- Constructor methods (optional - if you don't provide one, the parent's constructor will be called upon instantiation)
- Working instanceof
- Private/privileged properties/methods
- Parent properties/methods accessible through parent parameter
Usage
var HelloWorld = Class.extend(function() {
this.hello = 'Hello '; // public property
var world = 'World!'; // private/privileged property
this.constructor = function() { // constructor method (default name can be changed via constant)
// do nothing
};
this.say = function() { // public method
return privileged.call(this);
};
function privileged() { // private/privileged method
return this.hello + world;
}
});
var HelloWorldTwo = HelloWorld.extend(function(parent) {
this.hello = 'Hi ';
this.constructor = function() {
parent.constructor.apply(this, arguments); // call parent contructor
};
});
var helloWorld = new HelloWorld()
helloWorld.say() // 'Hello World!'
helloWorld instanceof HelloWorld // true
var helloWorldTwo = new HelloWorldTwo()
helloWorldTwo.say() // 'Hi World!'
helloWorldTwo instanceof HelloWorldTwo // true
helloWorldTwo instanceof HelloWorld // trueFor more examples see test/test.js.
Installation
NPM
npm install class-256.jsBower
bower install class-256.jsBrowser
<script src="https://github.com/koffeine/class-256.js/blob/master/dist/class.umd.min.js" charset="utf-8"></script>Files
| UMD | Minified | File |
|---|---|---|
| ✓ | ✓ | dist/class.umd.min.js |
| ✓ | dist/class.min.js | |
| ✓ | dist/class.umd.js | |
| dist/class.js |
Develop
Set up
npm installBuild
Running the following command will start Gulp, which will run ESLint, create the UMD version, run Mocha/Chai tests on node and on PhantomJS with Karma and run UglifyJS:
gulpLicense
Copyright © 2015 Horváth Kornél
Licensed under the MIT License.