Convert c-like functions to class methods.
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.
npm install --save to-methodimport 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 ❤ SarraMIT © Nicolas Gryman