Matt, This couldn't happen with any other js-engine, because of the ECMAScript semantics. The code that creates request handler closure is executed only once, which means that the closure is created only once.
Cheers, Fedor. On Mon, Aug 11, 2014 at 10:00 PM, Matt <[email protected]> wrote: > I don't know where you heard that, but it's not true of V8 (or I doubt of > any modern JS engine). There are plenty of benchmarks out there that can > prove this. > > You can however separate out for basic code hygiene - you get a lot of > indentation with nested callbacks. > > Matt. > > > On Sun, Aug 10, 2014 at 10:13 AM, David J Lima <[email protected]> > wrote: > >> In the plain javaScript world I've learned that nested functions can be >> problematic because the inner function is "re-created" every time the outer >> function is called. Apparently the inner function is garbage collected and >> the constant re-creation of it has a cost on performance. >> >> function outer(a) { >> function inner(arg1,arg2){ >> return arg1 + arg2; >> } >> return inner(a, 6); >> } >> myVar = outer(4); >> >> Are asynchronous callback functions typical in Node "re-created" every >> time they are fired? Take the following common Node construct: >> >> http.createServer(function (req, res) { >> res.writeHead(200, {'Content-Type': 'text/plain'}); >> res.end('Hello World\n'); >> }).listen(1337, '127.0.0.1'); >> >> Is the above callback "re-created" every time a client GETs or POSTs the >> server? If so, would it be better to always de-couple the callbacks as : >> >> function handleGET(req, res) { >> res.writeHead(200, {'Content-Type': 'text/plain'}); >> res.end('Hello World\n'); >> } >> >> http.createServer(handleGET).listen(1337, '127.0.0.1'); >> >> as a related bonus question, are event functions re-created too? Would >> they benefit from prior declaration? >> >> myObj.on('someEvent', function someFunction() {...}); >> >> vs. >> >> function someFunction() {...} >> myObj.on('someEvent', someFunction); >> >> -- >> Job board: http://jobs.nodejs.org/ >> New group rules: >> https://gist.github.com/othiym23/9886289#file-moderation-policy-md >> Old group rules: >> 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 unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected]. >> To post to this group, send email to [email protected]. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/nodejs/3101820e-7425-42b2-b001-3a173c2fbd68%40googlegroups.com >> <https://groups.google.com/d/msgid/nodejs/3101820e-7425-42b2-b001-3a173c2fbd68%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> For more options, visit https://groups.google.com/d/optout. >> > > -- > Job board: http://jobs.nodejs.org/ > New group rules: > https://gist.github.com/othiym23/9886289#file-moderation-policy-md > Old group rules: > 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 unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/nodejs/CAPJ5V2anFdsq8XQKDnu10H150so4qeaq8gVfBZPHUVtz8VbtFA%40mail.gmail.com > <https://groups.google.com/d/msgid/nodejs/CAPJ5V2anFdsq8XQKDnu10H150so4qeaq8gVfBZPHUVtz8VbtFA%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > > For more options, visit https://groups.google.com/d/optout. > -- Job board: http://jobs.nodejs.org/ New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md Old group rules: 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 unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/CAEv2VfJT0NK1KK_8_GR2M_%2BqQXHMZkM%2Bp8Y%3DWE6zjxHzkZ-VrA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
