decl

A class declaration module, that improves code structure and modularization.

Usage no npm install needed!

<script type="module">
  import decl from 'https://cdn.skypack.dev/decl';
</script>

README

NPM">

build status

Install

$ npm install decl

How to use

var cls = require('decl')({
    extend: ParentCls,

    constructor: function MyClass(arg1, arg2) {
        this.super('constructor', arg1, arg2);
    },

    method1: function() {
        //
    }
});

Class Statics

For defining static members on a class, simply pass a hash to the statics configuration key. These properties can then be accessed on class level. The this keyword resolves to the class within static members.

var cls = require('decl')({
    statics: function() {
        NAME: 'my/class',

        getName: function() {
            return this.NAME;
        }
    }
});

cls.getName() === 'my/class';
typeof (new cls).NAME === 'undefined';

ToDos

  • Improve the documentation
  • Add support for mixins/traits
  • Add support for inheritence of static members (static super?)