Javascript Reflection and Proxy

Here is the code example:

const t = {
	msg1: "hello",
	msg2: "world",
};

const h = {
	get: function(t, p, r) {
		console.log("target ->", t);
		console.log("prop -> ", p);
		console.log("receiver -> ", r);
		console.log("arguments -> ", arguments);
		return Reflect.get(...arguments);
	}
};

const proxy = new Proxy(t, h);

console.log("~~~~~~~~~~~~~~");

console.log("proxy.msg1 -> ", proxy.msg1);

console.log("~~~~~~~~~~~~~~");

console.log("proxy.foo -> ", proxy.foo);

Here is the running result of the above code:

References

Powered by Jekyll and Theme by solid