0

I'm trying to wrap a JS Set in a Proxy, and have the following interchange with node REPL

> const s = new Set()
undefined
> s.add(1)
Set(1) { 1 }
> const p = new Proxy(s, {})
undefined
> p
Proxy [ Set(1) { 1 }, {} ]
> p.add(1)
Uncaught:
TypeError: Method Set.prototype.add called on incompatible receiver [object Object]
    at Proxy.add (<anonymous>)

Is there any way to use Set wrapped in a Proxy?

PS. I'm assuming this will also be true for other built-ins like Map, WeakMap, etc?

EDIT: playing around further, binding a method and setting it on s does allow for it to be called without throwing an error.

Anton
  • 2,282
  • 26
  • 43

0 Answers0