Skip to content

Instantly share code, notes, and snippets.

@karlkori
Created September 30, 2016 14:28
Show Gist options
  • Select an option

  • Save karlkori/66b780fb767713999218e7c0112631ad to your computer and use it in GitHub Desktop.

Select an option

Save karlkori/66b780fb767713999218e7c0112631ad to your computer and use it in GitHub Desktop.
two directions constant
const Role = new Proxy({
ADMIN: 1,
USER: 2,
GUEST: 3
}, {
get(target, key) {
return isNaN(key) ? target[key] : _.findKey(target, val => val == key);
}
});
console.info(Role.ADMIN);
console.info(Role[1]);
console.info(Role[2]);
console.info(Role[3]);
console.info(Role[4]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment