Aha! That makes sense.
So, to summarize (as I understand it), the factory function exists so that
you can cleanly write things like:
s = require("http").createServer([listener])
instead of
s = new (require("http").Server)([listener])
Thanks, Scott!
Best,
-- Joel
On Monday, April 15, 2013 7:45:08 AM UTC-7, Scott González wrote:
>
> The reason node originally used these factories was a limitation in the
> C++ code <https://groups.google.com/d/msg/nodejs/GTaCdFPlweI/M0q38C3SJpkJ>.
> However,
> Isaac has also explained why he prefers not requiring the use of the new
> keyword<https://groups.google.com/forum/#!msg/nodejs/JI6CUkFksog/CEOMceoQuxQJ>
> .
>
>
> On Mon, Apr 15, 2013 at 10:41 AM, Bryce Baril <[email protected]<javascript:>
> > wrote:
>
>> One simple reason could be to allow instanceof checks the http.Server
>>
>> -Bryce
>>
>>
>> On Mon, Apr 15, 2013 at 7:36 AM, Joel Brandt <[email protected]<javascript:>
>> > wrote:
>>
>>> Hi,
>>>
>>> I'm curious about a patter that occurs at multiple places in the core
>>> node library.
>>>
>>> In the http module (and other places), there are both exported
>>> constructors and exported factory functions for the same objects (e.g.
>>> http.Server() and http.createServer()). In many cases, the factory
>>> functions are just wrappers around the constructor. For example, the code
>>> for http.createServer in v0.8.23 is simply:
>>>
>>> exports.createServer = function(requestListener) {
>>>> return new Server(requestListener);
>>>> };
>>>
>>>
>>> Can anyone explain why both are exported? Since createServer exists, I
>>> assume it's preferable to use that (perhaps for future-proofing one's
>>> code)? I'd also be interested to read any thoughts about when factory
>>> functions are preferable to constructors in the JS world.
>>>
>>> Thanks,
>>> -- Joel
>>>
>>> --
>>> --
>>> Job Board: http://jobs.nodejs.org/
>>> Posting guidelines:
>>> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
>>> You received this message because you are subscribed to the Google
>>> Groups "nodejs" group.
>>> To post to this group, send email to [email protected]<javascript:>
>>> To unsubscribe from this group, send email to
>>> [email protected] <javascript:>
>>> For more options, visit this group at
>>> http://groups.google.com/group/nodejs?hl=en?hl=en
>>>
>>> ---
>>> You received this message because you are subscribed to the Google
>>> Groups "nodejs" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to [email protected] <javascript:>.
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>
>>>
>>>
>>
>> --
>> --
>> Job Board: http://jobs.nodejs.org/
>> Posting guidelines:
>> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
>> You received this message because you are subscribed to the Google
>> Groups "nodejs" group.
>> To post to this group, send email to [email protected]<javascript:>
>> To unsubscribe from this group, send email to
>> [email protected] <javascript:>
>> For more options, visit this group at
>> http://groups.google.com/group/nodejs?hl=en?hl=en
>>
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "nodejs" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected] <javascript:>.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>
>>
>
>
--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.