I need to intercept property enumeration of an object (of a certain class) when iterating with a for..in loop. All I need to know is whether the object has been accessed in a for..in loop or not.
const myObject = new MyClass();
myObject["prop1"] = "val1";
myObject["prop2"] = "val2";
for (const p in myObject) {
console.info(p + ": " + myObject[p]);
}
Expected output:
object enumerated
prop1: val1
prop2: val2
I do have full control over the class of the objects. It doesn't need to work with any object type.
This would be normally done using proxies. Unfortunately the JS engine I am using has a bug that makes that impossible. Are there any other options? Maybe overriding the getOwnPropertyNames() method of MyClass?