-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy path3.js
More file actions
22 lines (21 loc) · 649 Bytes
/
3.js
File metadata and controls
22 lines (21 loc) · 649 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
function defineReactive(obj, key, val) {
Object.defineProperty(obj, key, {
enumerable: true,
configurable: true,
get: function() {
console.log('get');
return val;
},
set: function(newVal) {
console.log('set');
val += newVal;
}
});
}
let obj = {name: '成龙大哥', say: ':其实我之前是拒绝拍这个游戏广告的,'};
Object.keys(obj).forEach(k => {
defineReactive(obj, k, obj[k]);
});
console.log(obj.name + obj.say);
// obj.say = '后来我试玩了一下,哇,好热血,蛮好玩的';
// console.log(obj.name + obj.say);