Created
December 12, 2018 09:54
-
-
Save AaronLayton/1b430d787924937ed4e4c4437f4a0650 to your computer and use it in GitHub Desktop.
Just a simple enum for JavaScript ES5 / ES6
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
function Enumeration(obj) { | |
var myEnum = {}; | |
for (var key in obj) { | |
myEnum[key] = obj[key]; | |
} | |
myEnum.has = function(key) { | |
return this.hasOwnProperty(key); | |
}; | |
return Object.freeze(myEnum); | |
} | |
var test = new Enumeration({ | |
US: 1, | |
UK: 2, | |
Australia: 123 | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment