chtefi
7/2/2015 - 12:34 PM

Functional and context

Functional and context

// context based, functional? :-(
function foo() {
  const format = (name) => name.toUpperCase();
  const mapper = (item) => format(item);
  ['foo', 'bar'].map(mapper);
}

// no context based, functional! :-)
function bar() {
  const format = (name) => name.toUpperCase();
  const mapper = (fn) => (item) => fn(item);
  ['foo', 'bar'].map(mapper(format));
}