Last active
December 26, 2015 23:19
-
-
Save yakovkhalinsky/7229325 to your computer and use it in GitHub Desktop.
Possible implementation of Enums in Javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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