I have this JavaScript Proxy code
let globalVar = [];
const handler = {
get(target, name) {
const v = name in target ? target[name] : (target[name] = {});
return typeof v == "object" ? new Proxy(v, handler) : v;
},
set(target, prop, val) {
if (prop == "a") {
console.log("myObject["+prop+"] setto "+val);
}
else if (prop == "b") { //getting triggered
console.log("myObject["+prop+"] setto "+val);
}
else if (prop == "c") { //getting triggered
console.log("myObject["+prop+"] setto "+val);
}
else if (prop == "a.b") { //want to get something like this
console.log("myObject["+prop+"] setto "+val);
}
target[prop] = val;
}
};
globalVar = new Proxy(globalVar, handler);
globalVar.a.x = "55a";
globalVar.a.b = "55b";
globalVar.a.c = "et4" ;
witch i want to trigger set handler that can tell me the 2nd key and the 1st key.
meaning when i try to set globalVar.a.b = "55b"
only the line prop == "a.b"
would be triggered.
Now its trigger only using the 2nd key;