BTW, there are proxies [1], and one of the proxy hooks is to intercept calls [2].
[1]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy [2]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy/handler/apply Your "callable object" proposal would be literally as simple as this to implement: ```js const callable = Symbol.for("callable") const handler = { apply(target, thisArg, argsList) { return Reflect.apply(target[callable], thisArg, argsList) }, } function makeCallable(obj) { return new Proxy(obj, handler) } // Your example, ported const obj = makeCallable({ [callable]: function (...args) { return this[Symbol.for('value')] }, [Symbol.for(''value')]: 'value', }) assert(obj() === 'value') obj[callable] = () => 1 assert(obj() === 1) ``` ----- Isiah Meadows [email protected] www.isiahmeadows.com On Tue, Dec 4, 2018 at 12:02 PM 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

