Created
April 29, 2011 15:02
-
-
Save danheberden/948429 to your computer and use it in GitHub Desktop.
making $.when() always report one arg
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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