Skip to content

Instantly share code, notes, and snippets.

@danheberden
Created April 29, 2011 15:02
Show Gist options
  • Save danheberden/948429 to your computer and use it in GitHub Desktop.
Save danheberden/948429 to your computer and use it in GitHub Desktop.
making $.when() always report one arg
var getName = (function() {
var cache; // private cache
// gets assigned to getName
return function() {
// return the cache if it's valid or
return cache || $.ajax({
url: 'srv/echo',
data: { random: 1 },
success: function( data ) {
cache = data;
}
}).pipe( function( res ) {
return $.when( res );
});
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment