-
Notifications
You must be signed in to change notification settings - Fork 0
/
proxy.js
32 lines (26 loc) · 796 Bytes
/
proxy.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
//! The Proxy object enables you to create a proxy for another object, which can intercept and redefine fundamental operations for that object.
const john = { status: "looking for work" };
const handler = {
get: function (target, propName) {
console.log(target);
console.log(propName);
return target[propName];
},
};
// const agent = new Proxy(john, {});
// console.log(agent.status);
const agent = new Proxy(john, handler);
console.log(agent.status);
console.log("---------------------");
const ohi = { job: "student " };
const handler2 = {
set(target, propName, value) {
if (propName === "payRate") {
value = value * 0.85;
}
target[propName] = value;
},
};
const agent2 = new Proxy(ohi, handler2);
agent2.payRate = 1000;
console.log(agent2.payRate);