functionize

Turns an object into an object that can be called as a function.


Keywords
browser, functional, server, util
License
MIT
Install
bower install functionize

Documentation

Functionize

Turns an object into an object that can be called as a function.

build status

Installation

This module is installed via npm:

$ npm install functionize --save

Or Bower:

$ bower install functionize --save

Example

var functionize = require('functionize');

var object = {
  counter: 1,
  add: function(amt) {
    return this.counter += amt;
  }
};

// The normal way
console.log(object.counter); // 1
console.log(object.add(9)); // 10

// The functionized way
object = functionize(object, object.add);
console.log(object.counter); // 10
console.log(object(9)); // 19
console.log(object.add(1)); // 20 -- still works!

Pretty cool, eh? Take control of your objects!