Function expressions to arrow functions

JavaScript pattern

Converts function expressions to ES6 arrow functions


Apply with the Grit CLI
grit apply es6_arrow_functions

Transform function expressions

BEFORE
var increment = function (i) {
  return i + 1;
};

var remember = function (me) {
  this.you = me;
};

var sumToValue = function (x, y) {
  function Value(v) {
    this.value = v;
  }
  return new Value(x + y);
};

var times = (x, y) => {
  return x * y;
};
AFTER
var increment = (i) => {
  return i + 1;
};

var remember = function (me) {
  this.you = me;
};

var sumToValue = (x, y) => {
  function Value(v) {
    this.value = v;
  }
  return new Value(x + y);
};

var times = (x, y) => x * y;