JSPM

methmeth

1.1.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 81648
  • Score
    100M100P100Q157052F
  • License MIT

Execute a method out from an object.

Package Exports

  • methmeth

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (methmeth) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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!!!!
  • propprop - Pluck a property out of an object in an Array.prototype callback.