Skip to content

Instantly share code, notes, and snippets.

@MicheleBertoli
Created July 1, 2016 06:19
Show Gist options
  • Save MicheleBertoli/9681d0b86276b32081ee6392e9d46a3f to your computer and use it in GitHub Desktop.
Save MicheleBertoli/9681d0b86276b32081ee6392e9d46a3f to your computer and use it in GitHub Desktop.
Proxy
const proxied = target => {
const handler = {
get(target, key) {
if (typeof target[key] === 'function') {
return function (...args) {
const result = target[key].apply(this, args)
console.log('function', key, args, result)
return result
}
}
console.log('get', key, target[key])
return target[key]
},
set(target, key, value) {
console.log('set', key, value)
return target[key] = value
},
}
return new Proxy(target, handler)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment