vue2 动态劫持代理复习
程序员文章站
2022-07-02 21:20:54
...
我学习微信小程序的时候,又遇到了这个问题,再次再复习下
<script>
window.addEventListener("load", function() {
var data = {
name: "blue",
age: 18
}
var _this = {};
for (var item in data) {
// dynamic add property
Object.defineProperty(_this, item, {
get() {
console.log("get...")
return data[item];
},
set(newVal) {
console.log("set...")
data[item] = newVal;
}
})
}
console.log(_this.name)
_this.name = "kk";
console.log(_this.name)
});
</script>
推荐阅读