0.1.0 • Published 10 years ago
methodize v0.1.0
methodize
Makes a function behaves as a method.
Install
Download manually or with package-manager.
npm
npm install --save methodize
bower
bower install --save methodize
Example
var methodize = require('methodize');
var person = {
firstName: 'Gaius',
lastName: 'Baltar',
};
function getFullName(person) {
return person.firstName +' '+ person.lastName;
};
// Methodize the function and attaches it to the person object.
//
// The method name is retrieved from the original function if it is a
// named function.
//
// A custom name can be specified as a second parameter to attachTo().
methodize(getFullName).attachTo(person);
// Profit :)
console.log(person.getFullName());
Contributions
Contributions are very welcomed, either on the documentation or on the code.
You may:
- report any issue you've encountered;
- fork and create a pull request.
License
ISC © Julien Fontanet