callable objects ?

Russell Leggett russell.leggett at gmail.com
Tue Apr 17 14:41:24 PDT 2012


On Tue, Apr 17, 2012 at 4:44 PM, Brendan Eich <brendan at mozilla.org> wrote:

> Brendan Eich wrote:
>
>> Irakli Gozalishvili wrote:
>>
>>> It would be amazing to have clojure like protocols in JS  even without
>>> `IFn`. I think it's very good feet and very useful in JS where each library
>>> has it's own flavored API. I wrote more about it here:
>>> http://jeditoolkit.com/2012/**03/21/protocol-based-**
>>> polymorphism.html#post<http://jeditoolkit.com/2012/03/21/protocol-based-polymorphism.html#post>
>>>
>>
>> Still hoping Mark will weigh in.
>>
>
> Ok, I talked to Mark and Tom Van Cutsem, and they see no problem provided
> we prevent overriding built-in [[Call]] and [[Construct]] on function
> objects.
>
> Let there be private names @call and @construct (I'll spell them this way
> to avoid tedious imports of const bindings from "@std" or another built-in
> module).
>
> Let Clause 15.3.5 include new non-configurable, non-writable properties of
> function objects named by @call and @construct (built-in functions have
> only @call). The values are built-in and need a bit more thought than I can
> spare now, but see below: @call's value is close to the original value of
> Function.prototype.call, and @construct's value is straightforward enough I
> think.
>
> Change 11.2.2 "The new Operator" to use @construct not [[Construct]],
> passing the /argList// spread as actual positional parameters: (...argList).
>
> Change 11.2.3 "Function Calls" to use @call not [[Call]], passing the
> /thisValue/ and /argList/ according to the Function.prototype.call
> convention: (thisValue, ...argList).
>
> Change 11.4.3 "The typeof Operator", the table row with "Object (native or
> host and does implement [[Call]])" in column 1, to test not for [[Call]]
> and *not* for @call, rather to test [[NativeBrand]] === "Function" (see ES6
> draft 15.2.4.2 "Object.prototype.toString ( )").
>
> This last point is important: we do not want an object's typeof-type to
> change by giving it a @call property. But we do want to enable call and
> construct protocols to be built by users, by giving objects @call and
> @construct properties.
>
> This also simplifies direct proxies by allowing any proxy to have call and
> construct traps.
>
> Comments welcome.


What would happen if the object only defined one of these, but was used
with the wrong one? Let's say I create an object Foo with @call, but not
@construct, and then said new Foo()? Would it use @call and result in an
error? What about vice versa?

- Russ



>
>
> /be
> ______________________________**_________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/**listinfo/es-discuss<https://mail.mozilla.org/listinfo/es-discuss>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120417/03cfa16e/attachment-0001.html>


More information about the es-discuss mailing list