Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let Promise = function(cb) {
- this.q = [];
- cb(this.resolve.bind(this));
- };
- Promise.prototype.resolve = function(data) {
- this.q.pop()(data);
- };
- Promise.prototype.then = function(cb) {
- this.q.push(cb);
- };
- new Promise(function(resolve) {
- setTimeout(function() {
- resolve(10);
- }, 500);
- }).then(function(res) {
- console.log('res is', res);
- });
Add Comment
Please, Sign In to add comment