Skip to content

Instantly share code, notes, and snippets.

@MarkoCen
Created April 24, 2017 19:27
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MarkoCen/ec27b8cd42855fde8a245d43b7b081d0 to your computer and use it in GitHub Desktop.
Save MarkoCen/ec27b8cd42855fde8a245d43b7b081d0 to your computer and use it in GitHub Desktop.
Check if an object is a Promise
function isPromise(object){
if(Promise && Promise.resolve){
return Promise.resolve(object) == object;
}else{
throw "Promise not supported in your environment"
}
}
var i = 1;
var p = new Promise(function(resolve,reject){
resolve()
});
isPromise(i) // false
isPromise(p) // true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment