Scan Javascript for browser compatibility

前端 未结 4 1497
情书的邮戳
情书的邮戳 2021-02-04 03:41

Is there a tool out there to scan my Javascript code for functions that may not be present in all browsers?

My library is completely non-UI, so I don\'t care about how

4条回答
  •  情歌与酒
    2021-02-04 04:39

    UPDATE:

    Have a look at the answer from Stephan Vierkant that shows a plugin to solve this problem.


    There is no such tool, and there are a lot of browsers.

    I think there is an alternative approach to scanning your code for compatibility to "all" browsers, although this truly would be a useful thing. Most people do the following two things to assure some degree of cross-browser compatibility.

    Use a library

    You can use a library like underscore.js, jQuery, Dojo, Modernizr, etc. that wrap browser incompatibilities for you. So you can for example use jQuery.inArray, which will work in all browsers that jQuery covers with a common interface for you to use.

    Limit Browser support

    Decide which browsers you want to support with your application, state this on your website, and then test in these browsers. Either natively if you have them, or use something like browserstack to do the testing for browsers you dont have. This answer also lists more alternatives for this.

    And in the end there are best practices and personal experience to rely on when writing code.

提交回复
热议问题