JavaScript: Object Literal over Switch Statement

2018-02-24 ·
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')
Copyright © 2018 All rights reserved.
Powered by Kulfon.