function Promise(executor) {
this.thens = [];
if('function' === typeof executor) {
executor(this.resolve.bind(this));
}
};
Promise.prototype = {
constructor: Promise,
resolve: function(data) {
var callback = null;
for(var i=0,len=this.thens.length; i<len; i++) {
if('function' === typeof (callback = this.thens[i])) {
data = callback.call(this, data);
}
}
/*
while('function' === typeof (callback = this.thens.shift())) {
data = callback.call(this, data);
}
*/
},
then: function(n) {
return this.thens.push(n), this;
}
};
↧
低配版promise
↧