Skip to content

Instantly share code, notes, and snippets.

@clauswitt
Created November 14, 2011 07:47
Show Gist options
  • Select an option

  • Save clauswitt/1363471 to your computer and use it in GitHub Desktop.

Select an option

Save clauswitt/1363471 to your computer and use it in GitHub Desktop.
A Simplie Promise AMD module
define('SimplePromise', [], function() {
var constructor = function() {
_ = this;
var theHandler = function(response) {};
var theFunction= function() {};
var theThis;
this.then = function(fn, thisObject) {
handler = fn;
theThis = thisObject || _;
return _;
};
this.promise = function(fn) {
theFunction = fn;
return _;
};
this.run = function() {
runPromise(theFunction, arguments);
};
var runPromise = function(promise, args) {
setTimeout(function() {
handler(promise.apply(theThis, args));
}, 1);
};
return _;
}
return constructor;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment