ES6 Proxy listens for deep-seated objects

how does Proxy listen for changes to any deep-seated object?

for example:

let obj = {
  name: {
    first: "Hello",
    last: "World"
  },
  age: 20
}

let objx = new Proxy(obj, {
  set(target, key, value, receiver) {
    console.log(key);
    target[key] = value;
  }
})

objx.age = 18;
objx.name.first = "Hello!";

in this case, only objx.age, cannot listen for changes to the objx.name.first attribute

Mar.14,2022

you need to traverse the object deeply, and then proxy each object

Menu