Brand New Features in Underscore.js and Backbone.js by Pivots

April 1, 2013 David Lee

Just wanted to highlight a couple features that @brysgo and I contributed to these libraries using our beach time. They’ve since been accepted and merged.

First, backbone.js. We made a very simple change, one that hopefully makes a big difference to some — routes used to only take a hash but it can now take a function as well! For an example of how to use this, please check out the test. Why would you want to do this? The primary motivation was that it allowed for an inheritance-like scheme for defining routes (which is clearly illustrated in the test). For a full discussion, please see the thread. There is a very similar mechanism for defining view’s events using either a hash or a function, so we simply made routes consistent with that.

Next, underscore.js. We added a subtle new feature to the throttle() function where it takes an optional boolean flag indicating whether the throttled function gets called immediately at the start of the interval or at the trailing end of the interval. If you’re familiar with how the debounce() function works, then it has the same effect as its third parameter.

Any thoughts on these features? Would love to hear from you especially if you end up using either of these!

About the Author

Biography

Previous
Getting rid of "VMware Shared Folders" under OS X
Getting rid of "VMware Shared Folders" under OS X

The Scenario You have a fresh machine. But when you log in, you see a link on your desktop to VMware Shar...

Next
Keep gem configurations up-to-date with Rails generators
Keep gem configurations up-to-date with Rails generators

Many Ruby gems are packaged with a Rails generator that generates a configuration file. Keeping these gem c...

×

Subscribe to our Newsletter

!
Thank you!
Error - something went wrong!