Skip to content

Instantly share code, notes, and snippets.

@davemackintosh
Created November 11, 2020 10:04
Show Gist options
  • Save davemackintosh/4fe4a9868434712857f2a541d7612db8 to your computer and use it in GitHub Desktop.
Save davemackintosh/4fe4a9868434712857f2a541d7612db8 to your computer and use it in GitHub Desktop.
const config = {
"e02c2064-d961-4feb-lll4-558e0dd596d1": {
user: {
name: "Ian",
},
},
"f662b7aa-e2ff-4406-97c3-c0c6cb511159": {
user: {
name: "Greg",
},
},
"ce0699ad-3578-47d6-837c-2aaad02f4b4a": {
user: {
name: "Sandra",
},
},
};
function inConfig(inConfigKey) {
return new (class {
valueOf() {
return inConfigKey;
}
toString() {
return inConfigKey;
}
get name() {
return config[this.toString()].user.name;
}
})();
}
const key = inConfig("e02c2064-d961-4feb-b8e4-558e0dd596d1");
console.log("Key: %s", key);
console.log("Name: %s", key.name);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment