HNHacker News
TopNewBestAskShowJobs

panthomakos

49 karma · joined March 23, 2011

submissionscomments
panthomakos··on Avoiding Nested Callbacks in JavaScript
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.
panthomakos··on Avoiding Nested Callbacks in JavaScript
Absolutely - the code can be re-factored - but your example doesn't demonstrate that you can used named functions/callbacks within closures to further organize code.
panthomakos··on Avoiding Nested Callbacks in JavaScript
I think you make good points. The reason I used these simple examples was only for simplicity and to illustrate that named function callbacks can be used within closures rather than littering your global space with function declarations. More complex examples would probably have taken away from the core point of the article.
panthomakos··on Avoiding Nested Callbacks in JavaScript
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.
panthomakos··on Avoiding Nested Callbacks in JavaScript
But this is happening anyways with unnamed functions - they will be defined any time the top level function is called. The difference is really just whether or not you are naming your functions.