https://github.com/isruslan/popo
Stupid way to implement polymorphism in javascript
https://github.com/isruslan/popo
Last synced: 2 months ago
JSON representation
Stupid way to implement polymorphism in javascript
- Host: GitHub
- URL: https://github.com/isruslan/popo
- Owner: isRuslan
- License: mit
- Created: 2013-08-13T17:39:52.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2015-04-29T09:30:47.000Z (about 10 years ago)
- Last Synced: 2025-02-25T10:07:56.639Z (3 months ago)
- Language: JavaScript
- Homepage:
- Size: 2.39 MB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# popo [](http://travis-ci.org/isRuslan/popo)
> Simple way to implement polymorphism in javascript
## Install
Install with npm:
```
npm install --save popo
```Install with bower:
```
bower install --save popo
```## Usage
> There is only possible overload function by arguments number`Node.js`
```
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?';
```
`Browser````
popo({
0: function () {
return 'Hello Anonymous!';
},
1: function (name) {
return 'Hello ' + name + '!';
}
}, function otherWay () {
return 'Do I need to say Hello?';
});
```## TODO
- overload by type
- better implementation of `default` function## Test
From the repo root:
```
npm test
```
## License
Copyright (c) 2014 Ruslan Ismagilov. Licensed under the MIT license.