Best practices for JavaScript function parameters

Tags:

From time to time, people ask things like “should I use objects to pass function arguments”. I’m sure you recognize the pattern, as it’s common with many libraries: $.post({ a: ‘lot’, of: ‘properties’, live: ‘in’, here: ‘yep’ })$.post({ a: ‘lot’, of: ‘properties’, live: ‘in’, here: ‘yep’ }) But I would say this is not actually such a good idea. Let’s …

Short functions considered harmful: Staircase code

Tags:

Have you ever seen code which at first look seems good.. but then as you try to figure it out (maybe to fix a bug), it just feels… wrong? For some reason the code just feels really difficult to follow – for no obvious reason! In this post, I’m going to explain one such occurrence that I ran into in …

The best resources to learn about JavaScript Promises

Tags:

Promises can be both a blessing and a curse. They were supposed to clean the “callback pyramid of doom”, but instead they can often end up confusing (and I wanted to call that “The callback Temple of Doom”. It doesn’t really make sense in this context, I just like Indiana Jones) While promises do help, they are a lot more …

Mongoose models and unit tests: The definitive guide

Tags:

Mongoose is a great tool, as it helps you build Node apps which use MongoDB more easily. Instead of having to sprinkle the model-related logic all over the place, it’s easy to define the functionality as Mongoose models. Querying MongoDB for data also becomes quick and easy – and if you ever need some custom querying logic, that can be …

How to unit test ES6 code?

Tags:

ES6 is here today. Several browsers have almost all ES6 features available, and even Microsoft Edge is getting there. Tools like Babel help cover the parts which browsers don’t have yet. If you want to start using ES6 for development, that’s easy: there’s a lot of detailed information available. But what about testing? How do you write unit tests for …