Skip to content

Instantly share code, notes, and snippets.

@Gozala
Created November 29, 2009 14:38
Show Gist options
  • Save Gozala/244927 to your computer and use it in GitHub Desktop.
Save Gozala/244927 to your computer and use it in GitHub Desktop.
Function.prototype.promise = function() {
var method = this;
var callback;
var promise = {
returns: function(method) {
callback = method;
return promise;
}
};
method.yield = function() {
callback.apply(this, arguments);
}
return function() {
method.apply(this, arguments)
return promise;
}
}
/* @example */
var example = {
hello: function hello(name) {
setTimeout(function(){
hello.yield("Hello " + name + "!!");
}, 0);
}.promise()
}
example.hello("world").returns(function(msg) {
console.log(msg);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment