标签:get cep 通用 class logs 也有 对象 color val
1.proxy
用来拦截在一个对象上的指定操,如:
var engineer = { name: ‘Joe Sixpack‘, salary: 50 }; var interceptor = { //不仅仅有set方法,还有get...等通用的方法 set: function (receiver, property, value) { console.log(property, ‘is changed to‘, value); receiver[property] = value; } }; engineer = new Proxy(engineer, interceptor); engineer.salary = 60; //salary is changed to 60
也可以应用在多继承:
var foo = { foo: function () { console.log("foo") } }; var bar = { bar: function () { console.log("bar") } }; var sonOfFooBar = new Proxy({}, { get: function (target, name) { console.log("target=",target); return target[name] || foo[name] || bar[name]; } }) sonOfFooBar.foo(); //"foo",有foo方法,继承自对象foo sonOfFooBar.bar(); //"bar",也有bar方法,继承自对象bar
标签:get cep 通用 class logs 也有 对象 color val
原文地址:http://www.cnblogs.com/liuyinlei/p/7623585.html