The Javascript proxy function offers some interesting debugging features. For example, you can “protect” an object by placing it behind a proxy with a handler getthat issues if you access the undefined property. This helps to catch typos and other kinds of errors.
This can be used something like this:
class Something {
constructor()
{
this.foo = "bar";
allObjects.push(this);
}
};
function defend(o)
{
return new Proxy(o, DebugCheckHandler);
};
let rawSomething = new Something();
let defendedSomething = defend(rawSomething);
Code can be written diligently for use in terms only defendedSomething. However, in this example, the constructor Somethinggoes thissomewhere else (before allObjects). This results in the same effect as the use of rawSomethingand defendedSomethingfor the code base.
- , , rawSomething !== defendedSomething. , allObjects.includes(defendedSomething) false, rawSomething, includes ===.
, ?