Rome was not built in a day - 大前端
用法:
123456
var obj = {_name:"test"}obj.bind("name",function(){console.log("callback");})obj.name = "测试"; // 会触发bind方法
12345678910111213141516
if(!Object.prototype.bind){ Object.prototype.bind = function(key, callback){ var _key = "_" + key; Object.defineProperty(this, key, { get: function(){ return this[_key]; }, set: function(value){ if(value !== this[_key]){ this[_key] = value; callback(); } } }); }}