Search code examples
javascriptmethodsproxynumbersprototype

Can I assign Proxy to Number.prototype somehow?


Can I assign Proxy to Number.prototype somehow? I want to be able to call:

42..anyMethod


Solution

  • I just found the solution.

    Object.setPrototypeOf(Number.prototype, new Proxy({}, {
      get(target, prop, receiver) {
        return prop in target || typeof prop === 'symbol' ? target[prop] : { target, prop, receiver };
      }
    }));