Re: Fetch API

On Sun, Jun 1, 2014 at 2:19 PM, Domenic Denicola
<domenic@domenicdenicola.com> wrote:
> From: Tab Atkins Jr. [mailto:jackalmage@gmail.com]
>> Using NamedConstructor is identical to doing:
>>
>> ```js
>> class Foo { ... }
>> let Bar = Foo;
>> // now I can do "new Foo()" or "new Bar()", to the same effect.
>> ```
>
> Not true, since the constructors take different arguments.

Ah right, I forgot that the arguments are different.  This effectively
makes it a constructor with overrides, where the function you call it
with is taken as one of the arguments used for discriminating between
overrides.

Out of curiosity, would you be okay with it if it was just an
override?  That is, if "new Response(...)" took either set of
arguments for the ... part?  It sounds like you would be.

> Instead it is equivalent to
>
> ```js
> class Response {
>   constructor(body, init) { ... }
>   ...
> }
>
> function RedirectResponse(url, status = 302) {
>   return new Response(???, ???);
> }
> RedirectResponse.prototype = Response.prototype;
> ```
>
>> What invariants are you concerned about?
>
> In particular, we have that
>
> ```js
> RedirectResponse.prototype.constructor !== RedirectResponse
> (new RedirectResponse(...)).constructor !== RedirectResponse
> // Also, omitting the `new` does not throw a `TypeError`, like it does for real constructors.
> ```
>
> and possibly a few others I am forgetting.

This is identically a problem with the case I gave, as
Bar.prototype.constructor would be Foo, not Bar.  It's possible that
this is still a problem, it's just not unique to named constructors.
^_^

Since you suggested a static method, that suggests you're fine with
Response.Redirect(http://example.com) giving a new Response object,
right?  It's just the fact that RedirectResponse has a .prototype
pointing to Response.prototype that gives you pause?

Presumably RedirectResponse being a subtype would also be acceptable,
as its .prototype.constructor would be RedirectResponse?

~TJ

Received on Sunday, 1 June 2014 22:53:30 UTC