Callable objects protocol

T.J. Crowder tj.crowder at
Tue Dec 4 18:06:49 UTC 2018

On Tue, Dec 4, 2018 at 5:02 PM Sultan
<thysultan at> wrote:
> Something along the lines of Symbol.iterator protocol for defining
> callback objects i.e: Symbol.callable:

That's interesting. What's the primary motivation? Binding the data? That's
easily done with a closure ([fiddle[1]):

const obj = (() => {
    let value = 'value';
    return () => value;

console.log(obj() === 'value'); // true

It's a bit more verbose than one would like, but usually that's washed out
by the implementation (which is really trivial above).

You can also do it with a Proxy on a function, but it doesn't really buy
you anything.

Be interested to know more about why you want non-function callable objects.

-- T.J. Crowder

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list