[Javascript] Wrap Arrays with Proxy

In contrast to other built-ins, Arrays can be wrapped transparently:

const p = new Proxy(new Array(), {});

p.push('a');
assert.equal(p.length, 1);

p.length = 0;
assert.equal(p.length, 0);

The reason for Arrays being wrappable is that, even though property access is customized to make .length work, Array methods don’t rely on internal slots – they are generic.

posted @ 2020-08-27 02:52  Zhentiw  阅读(150)  评论(0编辑  收藏  举报