var obj = {};Object.defineProperty(obj, "name", { get : function(){ return this._name;}, set: function(val){ this._name = val;}});那如何监听 var string="a" 的string变量变化呢?
1 回答
一只斗牛犬
TA贡献1784条经验 获得超2个赞
Object.defineProperty(window, "mystring", {
get : function(){ console.log("get");return this._name;},
set: function(val){ console.log("set");this._name = val;}
});
添加回答
举报
0/150
提交
取消