Modernizr is a library that detects a discovery function. You can use the library as it is, and then query it for the functions you want, or you can see how it works for certain functions that you want to detect and copy into your own code.
How you discover a function for a given function depends entirely on the particular function.
Actual function detection is usually pretty quick (maybe even faster than extracting / saving something in a cookie). In addition, it is best for you to perform a function detection function every time a user updates to a new version of his browser whose capabilities are changing.
For example, if you want to know if you can use the .forEach () method for an Array object, you can simply use this:
if ( Array.prototype.forEach ) {
source share