JavaScript: Object Literal over Switch Statement


2018-02-24 · 1 min read
function dispatchStatus(status) {
  const statuses = {
    'accepted': () => 'This is accepted',
    'rejected': () => 'This is rejected',
    'pending': () => 'This is pending',
    'default': () => 'Status unknown'
  };
  return (statuses[status] || statuses['default'])();
}
 
dispatchStatus('accepted')