Skip to content

ngryman/to-method

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

to-method

Convert c-like functions to class methods.

travis codecov

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

npm install --save to-method

Usage

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

About

⚓ Convert c-like functions to class methods.

Resources

License

Stars

Watchers

Forks

Packages