JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 14
  • Score
    100M100P100Q46999F
  • License ISC

Yet another way to create class-like object/functions with private, public, and static members

Package Exports

  • classer

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 (classer) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

classer

Install

$ npm i classer

Use

my-class.js:

/**
* private static:
**/
const H_LOOKUP = {
    a: 'arnold',
    b: 'batman',	
};

/**
* class:
**/
const local = classer('MyClass', (h_config) => {
    
    /**
    * private fields:
    **/
    let {
        name: s_name,
        limit: n_limit,
    } = h_config;

    /**
    * private methods:
    **/
    const run_task = () => {
        n_limit += 1;
    };

    /**
    * public:
    **/
    return classer.operator(function() {
        return 'hi! I am '+s_name;
    }, {
        org: 2,

        getName() {
            return s_name;
        },

        change() {
            run_task();
        },
    };
},
    /**
    * public static:
    **/
    {
    
    help: () => {
        return 'help yourself';
    },
});

// exports
export default local;

index.js:

import MyClass from './my-class.js';

let instance = MyClass({name: 'cartman', limit: 5});
instance(); // 'hi! I am cartman'
instance.getName(); // 'cartman'
MyClass.help(); // 'help yourself'