const obj = { a: 1 };
const handlers = {
// declare a get method on the handler object
get(target, key, context) {
console.log( "accessing: ", key );
// forward the operation onto the target (obj) via Reflect.get
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/get
// target is the object, key is the key being accessed, context is the proxy
return Reflect.get(
target, key, context
);
}
};
const pobj = new Proxy( obj, handlers );
obj.a; // 1
pobj.a;
// accessing: a
// 1
Created
July 18, 2018 07:19
-
-
Save amysimmons/4d0b94b2df4b651d176b6f10f1d30add to your computer and use it in GitHub Desktop.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment