Around the beginning of June, I came across this article
by Joel Hooks
. I decided to jump in with both feet and made a conscious effort to not write any type of loop for the next 30 days (just to test it out), and I still haven’t written one. Underscore is now a tool that I’m going to keep in my utility belt.
First, let’s talk about Underscore.js
“If I sit down in front of a blank HTML page, and want to start being productive immediately, what do I need?”
- Underscore.js website
(to compare, minified jQuery 2.1.1 is 83kb), and after using it for a while, it’s super powerful.
Underscore Highlight Reel
I just want to go over a few of the underscore functions that I’ve found incredibly useful (and am using them in production client code). First, without a doubt the most useful function that I’ve used is the each function:
Use it now, and you will be a better developer for it. For me, this was the gateway drug into the world of underscore. Once I was comfortable with each, I slowly delved into the rest of the library to see what I could use.
Another useful function is debounce:
Instead of hashing out some timers and different detections, this handy helper packages it all up very nicely for us. I’m loving this one too.
Want to recreate an object without looping through it and finding certain properties? No problem, underscore has you covered with pick:
Sometimes you don’t need all of the properties in an object, so why have them clutter up your application?
These are just a few of MANY incredibly useful functions underscore provides. I encourage you to take a look at the full offering on the underscore website
– it provides examples for each function, is super detailed, and easy to understand.
Clean Before Lean on a Team
So go ahead, read Joel’s article and start the 30-day no-loop challenge today.