123456 |
- /*!
- * easy-promise v0.0.3
- * Homepage https://github.com/cnwhy/promise#readme
- * License BSD-2-Clause
- */
- !function e(t,n,r){function o(s,u){if(!n[s]){if(!t[s]){var f="function"==typeof require&&require;if(!u&&f)return f(s,!0);if(i)return i(s,!0);throw new Error("Cannot find module '"+s+"'")}var c=n[s]={exports:{}};t[s][0].call(c.exports,function(e){var n=t[s][1][e];return o(n?n:e)},c,c.exports,e,t,n,r)}return n[s].exports}for(var i="function"==typeof require&&require,s=0;s<r.length;s++)o(r[s]);return o}({1:[function(e,t,n){!function(e,t){if("function"==typeof define&&(define.amd||define.cmd))define([],t);else{if("undefined"==typeof window&&"undefined"==typeof self)throw new Error("加载 "+e+" 模块失败!,请检查您的环境!");var n="undefined"!=typeof window?window:self;n[e]=t()}}("Promise",function(){var t=e("./setTimeout");return t})},{"./setTimeout":2}],2:[function(e,t,n){t.exports=e("./src")(function(e){setTimeout(e,0)})},{"./src":3}],3:[function(e,t,n){"use strict";t.exports=function(e){function t(e,r){if(n(r))r.then(e.resolve,e.reject);else if(!r||"function"!=typeof r&&"object"!=typeof r)e.resolve(r);else{var o,i=!1;try{o=r.then,"function"==typeof o?o.call(r,function(n){i||(i=!0,t(e,n))},function(t){i||(i=!0,e.reject(t))}):e.resolve(r)}catch(t){i||(i=!0,e.reject(t))}}}function n(e){return e instanceof r}function r(e){function n(e){o.call(f,1,e)}function r(e){o.call(f,0,e)}function i(e){if(!c)return c=!0,f===e?r(new TypeError("The promise and its value refer to the same object")):void t({resolve:n,reject:r},e)}function s(e){c||(c=!0,r(e))}var f=this;this.status=-1,this._events=[];var c=!1;if(this.resolve=i,this.reject=s,e!==u&&"function"==typeof e)try{e(this.resolve,this.reject)}catch(e){this.reject(e)}}function o(e,t){var n=this;~this.status||(this.status=e,e?this.value=t:this.reason=t,i.call(n))}function i(){if(~this.status){for(var e=this,t=e._events,n=e.status?e.value:e.reason,r=e.status?0:1,o=0;o<t.length;o++)!function(t){var o=t[r],i=t[2];s(o,n,i,e.status)}(t[o]);t=[]}}function s(t,n,r,o){var i=r.resolve,s=r.reject;"function"==typeof t?e(function(){var e;try{e=t(n)}catch(e){return void s(e)}i(e)}):o?i(n):s(n)}var u=function(){};return r.defer=function(){var e=new r(u);return{promise:e,resolve:e.resolve,reject:e.reject}},r.resolve=function(e){return n(e)?e:new r(function(t,n){t(e)})},r.reject=function(e){return new r(function(t,n){n(e)})},Promise.prototype.toString=function(){return"[object Promise]"},r.prototype.then=function(e,t){var n=this.status,o=r.defer(),i=o.promise;return~n?n&&"function"==typeof e?s(e,this.value,i,n):n||"function"!=typeof t?n?o.resolve(this.value):o.reject(this.reason):s(t,this.reason,i,n):this._events.push([e,t,i]),i},r}},{}]},{},[1]);
|