Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/isruslan/popo
Stupid way to implement polymorphism in javascript
https://github.com/isruslan/popo
Last synced: about 1 month 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 (over 11 years ago)
- Default Branch: master
- Last Pushed: 2015-04-29T09:30:47.000Z (over 9 years ago)
- Last Synced: 2024-11-13T17:51:12.663Z (about 1 month 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 [![Build Status](https://secure.travis-ci.org/isRuslan/popo.png?branch=master)](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.