0

What I'm trying to create is a callable object. I was thinking with an ES6 Proxy it is possible, or at least the docs doesn't mention that this shouldn't be possible (but the example only shows how to create a Proxy for a function):

const object = { foo: 'bar' }

const callableProxy = new Proxy(object, {
  apply(target, self, args) {
    console.log('Yay!')
  }
})

callableProxy()

But this just throws TypeError: callableProxy is not a function on both node and chrome. What is the situation here? Is this by design? If it is, why on earth would the standard exclude this option?

Balázs Édes
  • 13,452
  • 6
  • 54
  • 89
  • Why are you trying to do this? – Bergi Apr 04 '17 at 16:16
  • Yes, this is by design: a proxy is only callable when also its target is callable, and this callability never changes. This e.g. makes the proxy still work when the `apply` handler is changed or deleted (or changed to the default `Reflect` implementation) – Bergi Apr 04 '17 at 16:17

0 Answers0