Monday, May 13, 2024
 Popular · Latest · Hot · Upcoming
188
rated 0 times [  192] [ 4]  / answers: 1 / hits: 26604  / 10 Years ago, wed, march 19, 2014, 12:00:00

Does anyone know, using Modernizr or otherwise, if there is a way to detect if the Promise feature is enabled in a browser?



I have a polyfill for the functionality, but only want to apply it if the browser does not have a native implementation.


More From » promise

 Answers
13

Update Dec 11 - 2016: All evergreen versions of browsers now support promises. They are safe to use.






Update Nov 14 - 2016: Chrome, Firefox, Safari and IE all now have experimental support for promises in their dev channels. The specification has settled. I would still not rely on the implementation just yet and would use a library but this might change in a few months.






No browsers support promises natively in a reliable way. The specification might change - at least for a few more months. My suggestion is use a fast promise library like Bluebird.



If you want to check if native promises are enabled - you can do :



if(typeof Promise !== undefined && Promise.toString().indexOf([native code]) !== -1){
//here
}


As others suggested, just checking if there is a Promise object can be done by if(Promise) but I strongly suggest against it since different libraries have different APIs for creation of promises etc.


[#71897] Tuesday, March 18, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
janettejordynm

Total Points: 550
Total Questions: 94
Total Answers: 98

Location: Senegal
Member since Fri, Aug 21, 2020
4 Years ago
janettejordynm questions
Tue, Nov 24, 20, 00:00, 4 Years ago
Sat, May 23, 20, 00:00, 4 Years ago
Mon, Apr 6, 20, 00:00, 4 Years ago
Tue, Feb 18, 20, 00:00, 4 Years ago
;