Here's my original answer, which has since been ratified in the spec as the way to test for a promise:
Promise.resolve(obj) == obj
This works because the algorithm explicitly demands that Promise.resolve must return the exact object passed in if and only if it is a promise by the definition of the spec.
I have another answer here, which used to say this, but I changed it to something else when it didn't work with Safari at that time. That was a year ago, and this now works reliably even in Safari.
I would have edited my original answer, except that felt wrong, given that more people by now have voted for the altered solution in that answer than the original. I believe this is the better answer, and I hope you agree.
ES6:
Here's my original answer, which has since been ratified in the spec as the way to test for a promise:
This works because the algorithm explicitly demands that
Promise.resolve
must return the exact object passed in if and only if it is a promise by the definition of the spec.I have another answer here, which used to say this, but I changed it to something else when it didn't work with Safari at that time. That was a year ago, and this now works reliably even in Safari.
I would have edited my original answer, except that felt wrong, given that more people by now have voted for the altered solution in that answer than the original. I believe this is the better answer, and I hope you agree.