Skip to main content

Posts

Showing posts from July, 2013

Anonymous Functions vs Named Functions for Node.js

I am a fan of anonymous functions, it just makes like easier and I find the syntax of passing functions around more expressive. Only problem I have found though is that when you have a bug, anonymous functions can give you a bit of a headache when tracking down what went wrong. In the first example createServer is passed an anonymous function that gets called back. If something goes wrong you the error message is something like: C:\Node\imageshare\server.js:14         route(pathName);         ^ TypeError: undefined is not a function     at Server. (C:\Node\imageshare\server.js:14:9)     at Server.emit (events.js:70:17)     at HTTPParser.onIncoming (http.js:1610:12)     at HTTPParser.parserOnHeadersComplete [as onHeadersComplete] (http.js:91:29)     at Socket.ondata (http.js:1506:22)     at TCP.onread (net.js:374:27) Which although is easy enough to track down in this example, you can see that the name of the function is not listed because it doesn't