Skip to content

Instantly share code, notes, and snippets.

@MhdSyrwan
Last active May 31, 2016 15:10
Show Gist options
  • Save MhdSyrwan/dea89f37f5057d6d079e98c697ffa3cf to your computer and use it in GitHub Desktop.
Save MhdSyrwan/dea89f37f5057d6d079e98c697ffa3cf to your computer and use it in GitHub Desktop.
const POSITION = (function() {
var inner = {};
Object.defineProperty(inner, 'left', {
writable: false,
value: 1
})
Object.defineProperty(inner, 'right', {
writable: false,
value: 2
})
Object.defineProperty(inner, 'middle', {
writable: false,
value: 3
})
return inner;
})();
console.log(POSITION.left);
function ENUM(values) {
var inner = {};
for(var i=0; i < values.length; i++) {
Object.defineProperty(inner, values[i], {
writable: false,
value: i + 1
})
}
return inner;
}
POSITION = ENUM(['left', 'right', 'middle']);
console.log(POSITION.left);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment