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

My Github Page: https://github.com/liweinan

Powered by Jekyll and Theme by solid

If you have any question want to ask or find bugs regarding with my blog posts, please report it here:
https://github.com/liweinan/liweinan.github.io/issues