Guest User

Untitled

a guest
Dec 10th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.34 KB | None | 0 0
  1. let Promise = function(cb) {
  2. this.q = [];
  3.  
  4. cb(this.resolve.bind(this));
  5. };
  6.  
  7. Promise.prototype.resolve = function(data) {
  8. this.q.pop()(data);
  9. };
  10.  
  11. Promise.prototype.then = function(cb) {
  12. this.q.push(cb);
  13. };
  14.  
  15. new Promise(function(resolve) {
  16. setTimeout(function() {
  17. resolve(10);
  18. }, 500);
  19. }).then(function(res) {
  20. console.log('res is', res);
  21. });
Add Comment
Please, Sign In to add comment