Inline function as method

Inline a standalone function that is only used as a property value.

Inline function as method

Sometimes functions are only used as property values. In such cases, you can convert the functions into methods.

Before (Example)

function aFunction(aParameter) {
  doSomething(aParameter);
}

const anObject = {
  aMethod: aFunction
};

Refactoring Steps

  1. Convert the named function into a variable that contains the function expression
  2. Inline the variable
  3. Convert the function to an object method

After (Example)

const anObject = {
  aMethod(aParameter) {
    doSomething(aParameter);
  }
};

Learn More