Skip to content

Instantly share code, notes, and snippets.

@thephilip
Created August 17, 2017 15:24
Show Gist options
  • Save thephilip/83c7003e7285a4a40d09c1910acff7ab to your computer and use it in GitHub Desktop.
Save thephilip/83c7003e7285a4a40d09c1910acff7ab to your computer and use it in GitHub Desktop.
Enumerated types in JavaScript
// create enumerated types in JavaScript
const EnumState;
(EnumState => { // ES6 IIFE!? No-ice
EnumState[EnumState["new"] = 1] = "new"
EnumState[EnumState["active"] = 2] = "active"
EnumState[EnumState["inactive"] = 3] = "inactive"
EnumState[EnumState["done"] = 4] = "done"
EnumState[EnumState["deleted"] = 5] = "deleted"
})( EnumState || ( EnumState = {} ) );
/*
EnumState {
1: "new", 2: "active", 3: "inactive", 4: "done", 5: "deleted",
new: 1, active: 2, inactive: 3, done: 4, deleted: 5
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment