DEV Community

Discussion on: Refactoring: My 6 favorite patterns

Collapse
 
ineam profile image
Amine M

very nice patterns, but I think on the number 6 you wanted to put it this way:

const myObject = { toName, punctuation, fromName };

// Before

function sayHello(myObject) {
  return `Hello, ${myObject.toName}${myObject.punctuation} From, ${myObject.fromName}.`
} 

sayHello(customerName, end, myName);

// After

function sayHello({ toName, punctuation, fromName }) {
  return `Hello, ${toName}${punctuation} From, ${fromName}.`
} 

sayHello(myObject);