W3C home > Mailing lists > Public > public-script-coord@w3.org > April to June 2013

Re: [promises] Difficulties with using constructors and promises together

From: Tab Atkins Jr. <jackalmage@gmail.com>
Date: Thu, 20 Jun 2013 12:38:57 -0700
Message-ID: <CAAWBYDCpWdoOfiDQrG_s=AUVkec1SaESPQLtgKvw1tRFOcq99A@mail.gmail.com>
To: "Mark S. Miller" <erights@google.com>
Cc: "public-script-coord@w3.org" <public-script-coord@w3.org>
On Thu, Jun 20, 2013 at 11:22 AM, Mark S. Miller <erights@google.com> wrote:
> Not sure I like this:
>
> What about invoking the constructor function as a function, i.e., without
> the "new". If it cannot create the object synchronously, then it can't
> return the object synchronously, so there really is no constructor function
> per se. So the name may as well just name a factory function which is just
> called normally.

Yeah, I don't like this either.  I think it violates Least Surprise -
when the new-less constructor function works, it usually just still
returns a new object in practice.  (I do this sometimes when I'm gonna
use a constructor a *ton* - just start the function with "if(!(this
instanceof MyClass)) return new MyClass(arg1, arg2);".)

~TJ
Received on Thursday, 20 June 2013 19:39:43 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 21:37:49 UTC