classify128

1.2.0 • Public • Published

Classify

Write JavaScript classes easily

How to use Classify

Use with Node.js / RequireJS

npm i -S classify128
const Classify = require("classify128");
 
const Logger = Classify({
    prototype: {
        log: function ()
        {
            console.log.apply(console, arguments);
        }
    }
});
 
const HasName = Classify({
    constructor: function (_super, name)
    {
        _super();
        
        this.name = name;
    },
    
    extends: Logger,
    
    prototype: {
        logName: function ()
        {
            this.log(this.name);
        }
    }
});
 
const Me = Classify({
    constructor: function (_super)
    {
        _super("Stefan Wimmer");
    },
    
    extends: HasName,
    
    prototype: {
        logTwice: function ()
        {
            this.logName();
            this.logName();
        }
    },
    
    static: {
        instance: function ()
        {
            return new Me();
        }
    }
});
 
Me.instance().logTwice();

Use in browser

<script src="classify128.js"></script>
var Logger = Classify({
    prototype: {
        log: function ()
        {
            console.log.apply(console, arguments);
        }
    }
});
 
var HasName = Classify({
    constructor: function (_super, name)
    {
        _super();
        
        this.name = name;
    },
    
    extends: Logger,
    
    prototype: {
        logName: function ()
        {
            this.log(this.name);
        }
    }
});
 
var Me = Classify({
    constructor: function (_super)
    {
        _super("Stefan Wimmer");
    },
    
    extends: HasName,
    
    prototype: {
        logTwice: function ()
        {
            this.logName();
            this.logName();
        }
    },
    
    static: {
        instance: function ()
        {
            return new Me();
        }
    }
});
 
Me.instance().logTwice();

Readme

Keywords

Package Sidebar

Install

npm i classify128

Weekly Downloads

2

Version

1.2.0

License

ISC

Last publish

Collaborators

  • stefanwimmer128