Skip to content

Instantly share code, notes, and snippets.

@yakovkhalinsky
Last active December 26, 2015 23:19
Show Gist options
  • Save yakovkhalinsky/7229325 to your computer and use it in GitHub Desktop.
Save yakovkhalinsky/7229325 to your computer and use it in GitHub Desktop.
Possible implementation of Enums in Javascript
var Enum;
module.exports = Enum = (function() {
function Enum(fields) {
var _this = this;
if (!(fields != null ? fields.length : void 0) || !Array.isArray(fields)) {
throw 'Fields must be an array of Strings';
}
fields.forEach(function(field) {
return _this[field.toUpperCase()] = field.toUpperCase();
});
}
return Enum;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment