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 256 byte JavaScript classical inheritance pattern library (or 390 bytes 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 // trueInstallation
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.js | ||
| ✓ | dist/class.min.js | |
| ✓ | dist/class.umd.js | |
| ✓ | ✓ | dist/class.umd.min.js |
Develop
Running the following command will run ESLint, create the UMD version, run the test and run uglify:gulp clean build
License
Copyright © 2015 Horváth Kornél
Licensed under the MIT License.