Complete Minimal Classes

Kevin Smith khs4473 at
Sun Apr 8 20:02:07 PDT 2012

> I always disliked that some functions in ECMAScript 5 can be invoked as
> either a function or a constructor. What would you want an entity Foo for
> that can be invoked in two ways? E.g.:
>      new Foo(...)
>      Foo(...)

Maybe Brendan can answer that one?  : )

Seriously, though, it's a fair question.  My first response is that since
the Chapter 15 "classes" exhibit this behavior, we should be able to fully
express it in a class syntax.

But beyond that, how should we deal with this situation?  We could make
classes *not* implement [[Call]], but that would mean we'd have functions
that didn't implement [[Call]], which is (AFAIK) truly novel and perhaps a
little bizarre.  I don't see that happening, but I could be wrong.

So if [[Call]]/[[Construct]] duality is a fact, how *should* we deal with

1)  Ignore the possibility of the constructor being [[Call]]ed.  This is
the typical response, because it's the easiest.  It's also the most

2)  Use a best-effort approximation to detect a [[Call]] as in:

3) Separate the two behaviors into separate bodies, with a reasonable
default for the [[Call]] operation.

I think (3) makes the most sense.  What do you think?

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

More information about the es-discuss mailing list