JSFiddle - React, Tailwind, and code Playground

by Peter Hozák

JavaScript

function resource_action(resource, action, amount) {
  alert([resource, action,amount].join(', '));
};

var resources = ['wood', 'wheat', 'gold', 'meat'];
var actions = ['get', 'set', 'add', 'sub'];

var res = resources.reduce(function(res, r) {
  res[r] = actions.reduce(function(act, a) {
    act[a] = function(amount) {
      return resource_action(r, a, amount);
    };
    return act;
  }, {})
  return res;
}, {});

res.gold.add(10);