- Doing stuff in the terminal is not scary at all
- npm is not only for getting packages
- Package.json is a mighty tool
- Git is not that hard, but I need to refresh my knowledge
- Callback function is cool stuff, and I even know how to write them - this post
- mocha is cool both as framework and test runner
- Should is a nice way to do asserts
- monk is an easy way to access mongo
- Express is best without generators
- supertest is a nice way to test an api
Callbacks is pretty easy on the concept level; a function does something and then “call back” to the caller when the work is done. The callback is simply a function that you pass to the function as a parameter. Like this function:
Quite simply (eh … not really the first time I saw this but anyway) doSomething will execute using 123 as the p parameter. It will finally call the callback function and hence execute my little anonymous function that does the console.log.
It took some time to wrap my head around this. And Yes, I know that promises is the new kid on the block, but I haven’t come there yet.
The first time it really clicked for me was actually when I started to write my code in another way. It was since I messed up the parentheses, curlys and semicolons a lot. So I write (most often) my function calls in this sequence, which helped me realise that the function is just another parameter. It also saved me from a lot of JSLint errors.
After awhile this way of writing will get boring and tedious so I will stop. Right now it helps me understand the structure so I’ll keep doing this.