Created
April 24, 2017 19:27
-
-
Save MarkoCen/ec27b8cd42855fde8a245d43b7b081d0 to your computer and use it in GitHub Desktop.
Check if an object is a Promise
This file contains hidden or 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
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