Created
November 14, 2011 07:47
-
-
Save clauswitt/1363471 to your computer and use it in GitHub Desktop.
A Simplie Promise AMD module
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
| 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