How to use javascript proxy for nested objects

前端 未结 4 772
礼貌的吻别
礼貌的吻别 2020-12-02 13:22

I have this code in js bin:

var validator = {
  set (target, key, value) {
    console.log(target);
    console.log(key);
    console.log(value);
    if(isO         


        
4条回答
  •  隐瞒了意图╮
    2020-12-02 13:29

    I published a library on GitHub that does this as well. It will also report to a callback function what modifications have taken place along with their full path.

    Michal's answer is good, but it creates a new Proxy every time a nested object is accessed. Depending on your usage, that could lead to a very large memory overhead.

提交回复
热议问题