I meant along these lines:
var http = require("http")
var s = http.createServer()
s instanceof http.Server // true
But I agree Scott's node history lesson is enlightening here
On Mon, Apr 15, 2013 at 7:48 AM, Joel Brandt <[email protected]> wrote:
> Hi Bryce,
>
> In general, that's a good guess. However, in the http.Server case, the
> Server constructor includes a "new" guard:
>
> function Server(requestListener) {
>> if (!(this instanceof Server)) return new Server(requestListener);
>> net.Server.call(this, { allowHalfOpen: true });
>> ...
>> }
>
>
> So, as I read it, the following should all be equivalent:
>
> s = http.createServer([listener])
>> s = http.Server([listener])
>> s = new http.Server([listener])
>
>
> btw, here's the code if you want to have a look:
> https://github.com/joyent/node/blob/v0.8.23-release/lib/http.js#L1748
>
> Best,
> -- Joel
>
>
>
> On Monday, April 15, 2013 7:41:34 AM UTC-7, [email protected] 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]> 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<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
>>> nodejs+un...@**googlegroups.com
>>>
>>> For more options, visit this group at
>>> http://groups.google.com/**group/nodejs?hl=en?hl=en<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 nodejs+un...@**googlegroups.com.
>>>
>>> For more options, visit
>>> https://groups.google.com/**groups/opt_out<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.
>
>
>
--
--
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.