Skip to content

Instantly share code, notes, and snippets.

@kakaroto
Created March 7, 2020 12:49
Show Gist options
  • Select an option

  • Save kakaroto/c544479caea31ed9a3a0874bf1d7fa64 to your computer and use it in GitHub Desktop.

Select an option

Save kakaroto/c544479caea31ed9a3a0874bf1d7fa64 to your computer and use it in GitHub Desktop.
Proxy to look at what get/set/call happens in an object
const rand = Math.round(Math.random() * 1000);
const proxy = new Proxy(toProxy, {
get: (obj, prop) => {
const value = obj[prop];
console.log("GET : ", rand, prop, value);
if (value instanceof Function) {
return new Proxy(value, {
apply: (func, thisArg, argumentList) => {
console.log("APPLY : ", rand, prop, argumentList);
const ret = func.apply(thisArg, argumentList);
console.log("RETURN : ", rand, prop, ret);
return ret;
}
});
}
return value;
},
set: (obj, prop, value) => {
console.log("SET : ", rand, prop, value);
obj[prop] = value;
return true;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment