Skip to content

Instantly share code, notes, and snippets.

@BernhardPosselt
Created January 27, 2013 14:56
Show Gist options
  • Save BernhardPosselt/4648718 to your computer and use it in GitHub Desktop.
Save BernhardPosselt/4648718 to your computer and use it in GitHub Desktop.
function Promise(){
this.requestIsSuccess = false;
this.onSuccessCallback = false;
}
Promise.prototype.success = function(callback){
if(this.requestIsSuccess){
callback(this.data)
} else {
this.onSuccessCallback = callback;
}
}
Promise.prototype.requestSuccess = function(data){
if(this.onSuccessCallback){
this.onSuccessCallback(data);
} else {
this.data = data;
this.requestIsSuccess = true;
}
}
function post(url){
var promise = new Promise()
$.post(url, data, function(data){
promise.requestSuccess(data);
});
return promise;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment