Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ngryman/to-method
⚓ Convert c-like functions to class methods.
https://github.com/ngryman/to-method
Last synced: about 2 months ago
JSON representation
⚓ Convert c-like functions to class methods.
- Host: GitHub
- URL: https://github.com/ngryman/to-method
- Owner: ngryman
- License: mit
- Created: 2016-09-15T17:13:03.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-05-04T11:09:03.000Z (over 6 years ago)
- Last Synced: 2024-07-26T17:54:50.163Z (about 2 months ago)
- Language: JavaScript
- Size: 9.77 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# to-method
> Convert c-like functions to class methods.
[![travis][travis-image]][travis-url] [![codecov][codecov-image]][codecov-url]
[travis-image]: https://img.shields.io/travis/ngryman/to-method.svg?style=flat
[travis-url]: https://travis-ci.org/ngryman/to-method
[codecov-image]: https://img.shields.io/codecov/c/github/ngryman/to-method.svg
[codecov-url]: https://codecov.io/github/ngryman/to-method**to-method** lets you bind `c-like` functions to classes. By `c-like` I mean
functions that always take the target data structure as the first argument.## Install
```bash
npm install --save to-method
```## Usage
```javascript
import toMethod from 'to-method'function love(person1, person2) {
console.log(`${person1.name} ❤ ${person2.name}`)
}class Person {
constructor(name) {
this.name = name
}
}
toMethod(Person, { love })const me = new Person('I')
const sarra = new Person('Sarra')
me.love(sarra)
// => I ❤ Sarra```
## License
MIT © [Nicolas Gryman](http://ngryman.sh)