首页 > 编程语言 > 详细

Javascript Promise Implementation

时间:2014-12-04 21:18:42      阅读:312      评论:0      收藏:0      [点我收藏+]
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

原文:http://www.cnblogs.com/hahazhu/p/4143640.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!