Skip to content

Instantly share code, notes, and snippets.

@copperwall
Created August 19, 2019 16: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 copperwall/2ae87260ebb7f22bdac4e83185d7b3a8 to your computer and use it in GitHub Desktop.
Save copperwall/2ae87260ebb7f22bdac4e83185d7b3a8 to your computer and use it in GitHub Desktop.
const myObject = {};
const loudObject = new Proxy({}, {
get(target, p) {
console.log(`Accessing key ${String(p)} at ${(new Error()).stack}`);
return target[p];
},
set(target, p, value) {
console.log(`Setting key ${String(p)} to ${String(value)} at ${(new Error()).stack}`);
target[p] = value;
return true;
}
});
// "Accessing key hello at Error
// at Object.get (/Users/user/projects/proxy/index.js:21:62)
// ..."
loudObject.hello;
// "Setting key hello to woop at Error
// at Object.get (/Users/user/projects/proxy/index.js:21:62)
// ..."
loudObject.hello = 'woop';
myObject.hello // 'woop'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment