Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Promise polyfill with jQuery Deferreds
function Promise(fn) {
this.promise = $.Deferred(function(dfd) {
fn(dfd.resolve, dfd.fail);
}).promise();
}
Promise.prototype.then = function(done, fail) {
this.promise.then(done, fail);
};
var promise = new Promise(function(resolve, fail) {
setTimeout(function() {
resolve();
}, 3000);
});
promise.then(function() {
console.log('done!');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment