methodify

Take a set of functions and make them methods of specified object

npm install methodify
1 downloads in the last week
15 downloads in the last month

methodify

Take a set of functions and make them methods of specified object.

Install

$ npm install methodify

Usage

methodify = require('methodify')

struct = {
  foo: 123,
  bar: 456
}

methodify(struct, {
  sum: sum,
  sub: sub
})

struct.sum()
// => 579

struct.sub()
// => -333

function sum (obj) {
  return obj.foo + obj.bar;
}

function sub (obj) {
  return obj.foo - obj.bar;
}
npm loves you