JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 28
  • Score
    100M100P100Q40494F
  • License MIT

256 byte JavaScript classical inheritance pattern library

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

npm version Bower version devDependency Status Travis

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 // true

Installation

NPM

npm install class-256.js

Bower

bower install class-256.js

Browser

<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.