Created
July 1, 2016 06:19
-
-
Save MicheleBertoli/9681d0b86276b32081ee6392e9d46a3f to your computer and use it in GitHub Desktop.
Proxy
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 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