JavaScript ES6 an example of the native support of the Proxy

Source:

<html>
<script>
var handler = {
    get: function(target, name) {
        debugger;
    	console.log("proxy handler called, context: " + target + " proxy name: " + name);
    	for( var pr in target){
    		console.log("property: " + pr + " native? " + target.hasOwnProperty(pr));
    	}
        return name in target ?
            target[name]:
            37;
    }
};

var p = new Proxy({ac: "Jerry"}, handler);
p.a = 1;
p.b = undefined;

console.log(p.a, p.b); // 1, undefined
console.log('c' in p, p.c); // false, 37





For more Jerry's original article, please pay attention to the public number "Wang Zixi":

Released 7169 original articles · won praise 654 · Views 1.24 million +

Guess you like

Origin blog.csdn.net/i042416/article/details/105087558