es6 添加事件监听

//定义被侦听的目标对象
var engineer = { name: 'Joe Sixpack', salary: 50 };

//定义处理程序
var interceptor = {
    set: function (receiver, property, value) {
        console.log(property, 'is changed to', value);
        receiver[property] = value;
    }
};

//创建代理以进行侦听
new Proxy(engineer, interceptor);
//做一些改动来触发代理
engineer.salary = 60;//控制台输出:salary is changed to 60
engineer.salary = 50;//控制台输出:salary is changed to 60

 

posted @ 2016-05-31 11:12  刘金宇  阅读(4040)  评论(0编辑  收藏  举报