JSPM

popo

0.1.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q33526F

Simple way to implement polymorphism in javascript

Package Exports

  • popo

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

Readme

popo Build Status

Simple way to implement polymorphism in javascript

Install

Install with npm:

npm install --save popo

Usage

There is only possible overload function by arguments number

var popo = require('popo');

var sayHello = popo({
    0: function () {
        return 'Hello Anonymous!';
    },
    1: function (name) {
        return 'Hello ' + name + '!';
    }
}, function otherWay () {
    return 'Do I need to say Hello?';
});

sayHello(); // 'Hello Anonymous!';
sayHello('Haruki'); // 'Hello Haruki!';
sayHello('Haruki', 'Murakami'); // 'Do I need to say Hello?';

TODO

  • overload by type
  • add browser support
  • better implementation of default function

Test

From the repo root:

npm test

License

Copyright (c) 2014 Ruslan Ismagilov. Licensed under the MIT license.