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

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! 😀

TC39

  1. function equals(x: number, y: number): boolean {
  2.     return x === y;
  3. }

Interesting proposal Proposal Types as Comments

Capitalize those types and this would look quite familiar…. cough ES4.

I have nothing against types so 👍 from me.

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