How about this:

```js

// the poly
if (!Symbol.callable)
  Symbol.callable = Symbol('callable');

// the setup
class Callable extends Function {
  constructor(object) {
    super('return arguments.callee[Symbol.callable](...arguments)');
    //            sloppy mode FTW!
    Object.setPrototypeOf(this, object);
  }
}


// the example
const obj = new Callable({
  [Symbol.callable](value) {
    return value + this.value;
  },
  value: 123
});

obj(7); // 130


```

On Wed, Dec 5, 2018 at 12:02 AM Sultan <[email protected]> wrote:

> Something along the lines of Symbol.iterator protocol for defining
> callback objects i.e: Symbol.callable:
>
> const obj = {
>     [Symbol.callable]: function (...args) { return
> this[Symbol.for('value')] },
>     [Symbol.for(''value')]: 'value',
> }
>
> assert(obj() === 'value')
> _______________________________________________
> es-discuss mailing list
> [email protected]
> https://mail.mozilla.org/listinfo/es-discuss
>
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to