Skip to content

Instantly share code, notes, and snippets.

@iddan
Created May 17, 2017 22:26
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 iddan/2bcdf89ccd21436f1d8f7337fcc94c08 to your computer and use it in GitHub Desktop.
Save iddan/2bcdf89ccd21436f1d8f7337fcc94c08 to your computer and use it in GitHub Desktop.
With Path
const WithPath = (target, path = []) => new Proxy(target, {
get(target, property, receiver) {
const value = target[property];
const thisPath = [...path, property];
return {
...(typeof value !== 'object' ? value : WithPath(value, thisPath)),
[WithPath.Path]: thisPath
};
}
});
WithPath.Path = Symbol('path');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment