DEV Community

loading...

Discussion on: Reverse switch?

Collapse
darthbob88 profile image
Raymond Price

The closest I've seen to that sort of wackiness is putting function pointers in an array and then indexing them, like so.

logTrue = () => console.log("It's true");
logFalse = () => console.log("It's false");
var foo = [logFalse, logTrue]
foo[+true]() //Chrome doesn't convert directly from true to 1, so have to do this to convert it.
/// "It's true"
Enter fullscreen mode Exit fullscreen mode

It's clever, but I would absolutely not allow it in production code.

Forem Open with the Forem app