Looping through an object and changing all values

后端 未结 7 1617
庸人自扰
庸人自扰 2020-12-29 21:42

I\'m having trouble looping through an object and changing all the values to something else, let\'s say I want to change all the values to the string \"redacted\". I need to

7条回答
  •  执念已碎
    2020-12-29 22:21

    Use a proxy:

    function superSecret(spy) {
      return new Proxy(spy, { get() { return "redacted"; } });
    }
    
    > superSecret(spy).id
    < "redacted"
    

提交回复
热议问题