10.1. Freezing by proxying: As requested, using a proxy allows you to intercept changes on an object. (See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy for more on this.) We use recursion to apply the proxy all the way down in case some attributes are objects themselves:
const proxySetAll = obj => {
Object.keys(obj).forEach(v => {
if (typeof obj[v] === "object") {
obj[v] = proxySetAll(obj[v]);
}
});
return new Proxy(obj, {
set(target, key, value) {
throw new Error("DON'T MODIFY ANYTHING IN ME");
},
deleteProperty(target, key) {
throw new Error("DON'T DELETE ANYTHING IN ME");
}
});
};
The following is the output of the preceding code. You'd probably require something other than a DON'T MODIFY...