阅读 46

JavaScript ES6对Proxy的原生支持的一个例子

源代码:

<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
复制代码





要获取更多Jerry的原创文章,请关注公众号"汪子熙":

文章分类
后端
文章标签