function createReactiveObject(target, callback) {
const proxy = new Proxy(target, {
set(obj, prop, value) {
if (value !== obj[prop]) {
const prev = obj[prop];
obj[prop] = value;
callback(`${prop}가 [${prev}] >> [${value}]로 변경되었습니다.`);
}
return true;
},
});
return proxy;
}
const a = {
강용: "A",
};
const b = createReactiveObject(a, console.log);
b.강용 = "B";
+-------------------+ HTTPS +------------------+
| | ----------> | |
| Proxy Server | | Local HTTP Server|
| | | |
+-------------------+ +------------------+
예시