methmeth
Execute a method out from an object.
Last updated 11 years ago by stephenplusplus .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install methmeth 
SYNC missed versions from official npm registry.

methmeth

Call a method on an object in an Array.prototype callback.

$ npm install --save methmeth
var meth = require('methmeth');

var friends = [
  {
    name: 'passy',
    hobby: 'carrots',
    getInfo: function () {
      return this.name + ' likes ' + this.hobby;
    }
  },
  {
    name: 'sindre',
    vehicle: 'unicorn taxi',
    getInfo: function () {
      return this.name + ' drives a ' + this.vehicle;
    }
  },
  {
    name: 'addy',
    invented: 'google *',
    getInfo: function () {
      return this.name + ' created ' + this.invented;
    }
  }
];

Before

var myFriends = friends.map(function (item) {
  return item.getInfo();
}).join('\n');
// passy likes carrots
// sindre drives a unicorn taxi
// addy created google *

After

friends.map(meth('getInfo')).join('\n');
// passy likes carrots
// sindre drives a unicorn taxi
// addy created google *

Pre-fill arguments

var friends = [
  {
    name: 'dave',
    passion: 'dried mango',
    getInfo: function (emotion) {
      return this.name + ' loves ' + this.passion + emotion;
    }
  }
];

friends.map(meth('getInfo', '!!!!')).join('\n');
// dave loves dried mango!!!!

Related

  • propprop - Pluck a property out of an object in an Array.prototype callback.

Current Tags

  • 1.1.0                                ...           latest (11 years ago)

3 Versions

  • 1.1.0                                ...           11 years ago
  • 1.0.0                                ...           11 years ago
  • 0.1.0                                ...           12 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 1
Last Month 0
Dependencies (0)
None
Dev Dependencies (1)

Copyright 2013 - present © cnpmjs.org | Home |