I have an object, i want to intercept in
opeartor access on the object.
e.g
myObject.operatorIn = ()=>throw new Error("You can't touch it :)")
I have an object, i want to intercept in
opeartor access on the object.
e.g
myObject.operatorIn = ()=>throw new Error("You can't touch it :)")
With a Proxy, you can create a has
trap to intercept uses of in
:
const myObject = {
foo: 'foo'
};
const myObjectProxy = new Proxy(
myObject,
{
has() {
throw new Error("You can't touch it");
}
}
);
console.log(myObjectProxy.foo);
console.log('foo' in myObjectProxy);