Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
jQuery style Deferreds for Underscore
branch: promises-tests

This branch is 10 commits behind master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.


Build Status

v0.3.0 (jQuery 1.8.0)

This is a port of jQuery.Deferred as an Underscore mixin, but it can be used without any depencencies. It currently matches the Deferred specifications and implementation from jQuery 1.8.0, with all the associated helpers.

Please note that as of 0.1.4 underscore.deferred will be ALL LOWERCASE on npm. The camelcasing was a mistake from the outset, please update your package.json appropriately.

Deferreds are great, let's take them everywhere

jQuery offers a robust, consistent and well documented API; this project aims to make it portable. jQuery added a handful of helper methods to their implementation of the Common.js Promises Spec, and they're faithfully reproduced without any dependencies.

underscore.deferred provides complete pairity with the jQuery Deferred API. Here are some of the method implemented:

For the complete API documentation, look to the jQuery Docs.

This project wouldn't exist if not for the the hard work and effort put into jQuery by its core team and contributors--thanks for making this possible!

Enhancements / Changes

So far, there's only 1 substantial difference between the jQuery API and underscore.deffered's. This may change in the future as new or divergent functionality is tested out, but rest assured that all differences will be called out here (and will have proper test coverage.)


underscore.deferred will apply an Array if it's the only argument, providing a useful shortcut for using when with an array of promises. Example:

var form = _.Deferred();
var auth = _.Deferred();

var promises = [ form.promise(), auth.promise() ];

  // ...



underscore.deferred works on the server and in the browser.

In the browser, just require it like you would any other file. If you're including Underscore on the page, make sure you include it before underscore.deferred. If you don't have Underscore, the plugin attaches to window._.

Addionally, underscore.Deferred can be used with the Ender.js build tool, if you're into that sort of thing.

On the server, simply install via npm and require normally. If you'd like to use it as an Underscore module, just do this:

var _ = require('underscore')._
_.mixin( require('underscore.deferred') );

But keep in mind that Underscore is not a strict requirement, and assigning it to another namespace will always work.


One time setup command:

$ npm install

To build with grunt

$ grunt

To run headless Qunit tests (must have phantomjs in your path)

$ grunt qunit



The goal is to slim the code footprint for robust deferreds as much as possible while maintaining mixin integration with Underscore and faithfullness to the jQuery API.

This is a work in progress, feel free to contribute.

MIT License.

Something went wrong with that request. Please try again.