[[Call]] vs. [[Construct]] using symbols

Herby Vojčík herby at mailbox.sk
Mon Oct 8 00:58:02 PDT 2012



Kevin Smith wrote:
>
>     It addresses a common pattern today, that looks like:
>
>     function Led( opts ) {
>        if ( !(this instanceof Led) ) {
>          return new Led( opts );
>        }
>
>        // ...
>     }
>
>
> Yes - I explored this idea back when we were discussing classes several
> months ago.  The thing that you have to consider is that sometimes users
> legitimately want to call [[Construct]] to initialize an existing
> object, and there needs to be a way to do that.

Firstly, there is super call which should invoke [[Construct]] and 
covers a lot of the cases for this, I presume.

And of course, there needs to be an API equivalent to call/apply 
(call-esque is enough now that we have spread).

> Kevin
Herby


More information about the es-discuss mailing list