Skip to content

Instantly share code, notes, and snippets.

@ppraksa
Last active March 22, 2017 12:48
Show Gist options
  • Save ppraksa/cb22ad740c3c1108dd543b67aacce84a to your computer and use it in GitHub Desktop.
Save ppraksa/cb22ad740c3c1108dd543b67aacce84a to your computer and use it in GitHub Desktop.
thenable
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