Last active
March 22, 2017 12:48
-
-
Save ppraksa/cb22ad740c3c1108dd543b67aacce84a to your computer and use it in GitHub Desktop.
thenable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var ASYNC = { | |
then: function then(o) { | |
typeof o === 'function' ? o() : false; | |
return { | |
then : this.then, | |
defer : this.defer | |
} | |
}, | |
defer: function then(o,t) { | |
return new Promise(function(res,rej) { | |
setTimeout(function() { | |
typeof o === 'function' ? o() : false; | |
res(); | |
}.bind(this), t); | |
}.bind(this)); | |
} | |
} | |
var b = Object.create(ASYNC); | |
b.then(function() { console.log('a') }).then(function() { console.log('b') }).defer(function() { console.log('c') },3000).then(function() { console.log('d') }).then(function() { console.log('e') }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment