Last active
August 29, 2015 14:17
-
-
Save DC3/d2c37399eae2f7f08d16 to your computer and use it in GitHub Desktop.
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
| do -> | |
| hasPromise = (window.Promise and window.Promise.all) | |
| hasjQuery = (($ = window.jQuery) and window.jQuery.fn.jquery) | |
| return if hasPromise or not hasjQuery | |
| Promise = (func) -> | |
| $.Deferred(({resolve, reject}) -> | |
| func.call null, resolve, reject | |
| ).promise() | |
| Promise.all = (arr) -> new Promise (resolve, reject) -> | |
| if Object::toString.call(arr) isnt '[object Array]' | |
| throw new TypeError 'Promise.all first param must be An iterable object' | |
| handleArguments = (args...) -> resolve(args) | |
| $.when(arr...).then(handleArguments , reject) | |
| Promise.resolve = -> $.Deferred().resolve arguments... | |
| Promise.reject = -> $.Deferred().reject arguments... | |
| # Promise.race = -> # WARN: jQuery do not have race method | |
| window.Promise = Promise |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment