首页 > 代码库 > Javascript Promise Implementation

Javascript Promise Implementation

var Promise=function(args){  this.callback=[];  var _this=this;  setTimeout(function() {    _this.done();  }, 0);};Promise.prototype.then=function(result){  this.callback.push(result);  return this;};Promise.prototype.when=function(){  throw new Error(‘Not implemented‘);};Promise.prototype.done=function(){  console.log(this.callback.join(‘,‘));  return this;};new Promise().then(10).then(11).then(12);

 

Javascript Promise Implementation