News for hackers. Stuff that matters.
Re:Avoiding Nested Callbacks in JavaScript by panthomakos on Thursday June 30, 2011 @01:37PM (#2714965)
The closures aren't meant to be more performant, they simply allow you to separate your code. It's not fair to compare the unnamed function example with the closure example, since the first doesn't create closures. If it did - which would be necessary to create both functions - the examples would be equally performant.
Re:Avoiding Nested Callbacks in JavaScript by tlrobinson on Thursday June 30, 2011 @01:55PM (#2715047)
The first and third examples are both creating closures. It doesn't matter if they're named or not. Any time you see the "function" keyword within another function, that's a closure.

Check out the performance of these three styles. #1 and #3 are almost identical, #2 is significantly faster: http://jsperf.com/closures-perf

Re:Avoiding Nested Callbacks in JavaScript by panthomakos on Thursday June 30, 2011 @02:18PM (#2715130)
You make a good point and thanks for the performance link. I should have been more clear. The first and third examples are only comprable in the way they create closures - which is equivalent, but they are meant to demonstrate different things. The first demonstrates nested callbacks while the last example demonstrates named functions that are organized by closures.