)
}
}
)
(
}
{
)
)
(
)
(
(
{
}
)
(
)
}
)
)
{
(
(
)
)
}
)
(
}

Enum Shorthand

  1. const toEnum = (...values) =>
  2.   Object.freeze(values.reduce((acc, curr) => {
  3.     acc[curr] = curr
  4.     return acc
  5.   }, {}))
  6.  
  7. const Graphics = toEnum(
  8.   'circle', 
  9.   'rect', 
  10.   'triangle'
  11. )
  12.  
  13. console.log(Graphics.circle)

I sure dislike fake enums in js. Something like this at least dries things up – but still, yuk! 😀

snippet.zone ~ 2021-24 /// {s/z}