-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpolyfillPromise-0.1.min.js
More file actions
5 lines (5 loc) · 2.03 KB
/
Copy pathpolyfillPromise-0.1.min.js
File metadata and controls
5 lines (5 loc) · 2.03 KB
1
2
3
4
5
(function(){var e,b;this.Promise&&"function"==typeof this.Promise&&(e=new this.Promise(function(){}));e&&this.Promise.all&&this.Promise.race&&this.Promise.reject&&this.Promise.resolve&&e.then&&e["catch"]?(e=null,b=this.Promise):(b=function Promise(a){var f=this,d=[],c,m=[],k,g="pending",n,l,h=function(b){c=arguments;for(var a=0;a<m.length;a++)m[a].apply(f,c);g="rejected"},e=function(a){k=arguments;for(var b=0;b<d.length;b++)d[b].apply(f,k);g="fulfilled"};if("function"===typeof a)try{a(e,h)}catch(p){g="rejected",
c=[p]}else throw Error("Promise argument "+a+" is not a function");f.then=function(a,h){if("fulfilled"===g&&"function"===typeof a)return b.resolve(a.apply(f,k));if("rejected"===g&&"function"===typeof h)return b.reject(h.apply(f,c));"function"===typeof h&&m.push(function(){l(h.apply(f,c))});"function"===typeof a&&(d[d.length]=function(){l(a.apply(f,k))});return new b(function(a){l=a})};f["catch"]=function(a){if("rejected"===g&&"function"===typeof a)return b.reject(a.apply(f,c));if("fulfilled"===g)return b.resolve.apply(f,
k);"function"===typeof a&&m.push(function(){n(a.apply(f,c))});d.push(function(){n.apply(f,k)});return new b(function(a){n=a})}},b.all=function(a){return new b(function(b,d){var c,m=[],k=0,g=a.length;(function l(h){var e=h;a[e].then(function(a){m[e]=a;++k===g&&(c="fulfilled",b(m))});a[e]["catch"](function(a){c||(c="rejected",d(a))});h<g-1&&l(++h)})(0)})},b.race=function(a){return new b(function(b,d){var c,e=a.length;(function g(n){var l=n;a[l].then(function(a){c||(c="fulfilled",b(a))});a[l]["catch"](function(a){c||
(c="rejected",d(a))});n<e-1&&g(++n)})(0)})},b.resolve=function(a){return a&&a.constructor&&a.constructor===b?a:a&&"function"===typeof a.then?new b(function(b,d){a.then(b,d)}):new b(function(b,d){b(a)})},b.reject=function(a){return new b(function(b,d){d(a)})});this.define&&this.define.amd&&"function"===typeof this.define?define([],function(){return b}):"undefined"!==typeof exports?("undefined"!==typeof module&&module.exports&&(exports=module.exports=b),exports.Promise=b):this.Promise||(this.Promise=
b)})();