码迷,mamicode.com
首页 > 编程语言 > 详细

Javascript Promise Implementation

时间:2014-12-04 21:19:41      阅读:154      评论:0      收藏:0      [点我收藏+]

标签:blog   io   ar   sp   java   on   div   log   bs   

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

标签:blog   io   ar   sp   java   on   div   log   bs   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!