Simplify your JavaScript code with normalizer functions

Tags:

Everyone loves a good if-else tower! What could be simpler than nesting a few conditionals? if(stuff) { if(more stuff) { haha(); } else { cool(); } }if(stuff) { if(more stuff) { haha(); } else { cool(); } } Ok – that isn’t the most amazing thing in the world. In a simple example like this, it isn’t too bad. But …

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 …

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 …

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 …