小编Pär*_*son的帖子

Javascript Proxy and spread syntax, combined with console.log

So, I was playing around with Proxy objects and while trying to see how they mix with spread syntax and de-structuring, I stubled upon this weird behavior:

const obj = {
  origAttr: 'hi'
}

const handler = {
  get(target, prop) {
    console.log(prop);
    return 1;
  },
  has(target, prop) {
    return true;
  },
  ownKeys(target) {
    return [...Reflect.ownKeys(target), 'a', 'b'];
  },
  getOwnPropertyDescriptor(target, key) {
    return {
      enumerable: true,
      configurable: true
    };
  }
}

const test = new Proxy(obj, handler);
const testSpread = { …
Run Code Online (Sandbox Code Playgroud)

javascript metaprogramming node.js proxy-pattern spread-syntax

7
推荐指数
1
解决办法
458
查看次数