thenable.js 337 B

12345678910111213
  1. function Thenable(thenable) {
  2. return thenable.then = thenable ;
  3. };
  4. Thenable.resolve = function(v){
  5. return Thenable.isThenable(v) ? v : {then:function(resolve){return resolve(v)}};
  6. };
  7. Thenable.isThenable = function(obj) {
  8. return obj && (obj instanceof Object) && typeof obj.then==="function";
  9. }
  10. module.exports = Thenable ;