Skip to content

Instantly share code, notes, and snippets.

@joshhunt
Created October 11, 2018 14:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshhunt/6bb0744f4f09b03b11b2e0b741349b62 to your computer and use it in GitHub Desktop.
Save joshhunt/6bb0744f4f09b03b11b2e0b741349b62 to your computer and use it in GitHub Desktop.
const makeMessages = (src = {}, path = []) =>
new Proxy(src, {
get(target, name) {
const newPath = [...path, name];
// For _any_ key on messages, return a function that returns the string-path to that key.
// Also, wrap that function in this proxy to do the same for any key on the function
return makeMessages(() => newPath.join('.'), newPath);
}
});
const messages = makeMessages();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment