From 7d50a56198f2992e908bc97b871210ec2b52123a Mon Sep 17 00:00:00 2001 From: kumavis Date: Tue, 10 Oct 2017 17:15:52 -0700 Subject: [PATCH] util - add obj-proxy --- app/scripts/lib/obj-proxy.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 app/scripts/lib/obj-proxy.js diff --git a/app/scripts/lib/obj-proxy.js b/app/scripts/lib/obj-proxy.js new file mode 100644 index 000000000..29ca1269f --- /dev/null +++ b/app/scripts/lib/obj-proxy.js @@ -0,0 +1,19 @@ +module.exports = function createObjectProxy(obj) { + let target = obj + const proxy = new Proxy({}, { + get: (obj, name) => { + // intercept setTarget + if (name === 'setTarget') return setTarget + return target[name] + }, + set: (obj, name, value) => { + target[name] = value + return true + }, + }) + return proxy + + function setTarget (obj) { + target = obj + } +} \ No newline at end of file