Created
August 19, 2019 16:26
-
-
Save copperwall/2ae87260ebb7f22bdac4e83185d7b3a8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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