JSFiddle - React, Tailwind, and code Playground
by Csaba Hellinger
JavaScript
const handler = {
get: (targetObj, propName, receiverProxy) => {
console.log('PROXY: From get.')
let ret = Reflect.get(targetObj, propName, receiverProxy)
if (typeof ret === 'function') {
ret = ret.bind(targetObj)
}
return ret
},
set: (targetObj, propName, propValue, receiverProxy) => {
console.log('PROXY: From set.')
return Reflect.set(targetObj, propName, propValue, receiverProxy)
},
}
const targetMap = new Map([
['key', 'value'],
])
const targetObj = {}
const proxy = new Proxy(targetMap, handler)
//proxy.super = 'man' // fires the setter
//const x = proxy.super // fires the getter