-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy path3-proxy.js
More file actions
24 lines (19 loc) · 476 Bytes
/
Copy path3-proxy.js
File metadata and controls
24 lines (19 loc) · 476 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
'use strict';
const data = { name: 'Marcus Aurelius', city: 'Rome', born: 121 };
const person = new Proxy(data, {
get(obj, key) {
console.log('get', key);
return obj[key];
},
set(obj, key, val) {
console.log('set', key, val);
obj[key] = val;
return true;
},
});
console.dir({ 'person.born': person.born });
console.dir({ 'person.year': person.year });
for (const key in person) {
console.dir({ key: person[key] });
}
person.name = 'Marcus';