简体   繁体   中英

Javascript code analysis and best practices

Are there any tools out there to help programmers that REALLY want type safety and the more stringent rules of a language like c# or java with javascript?

For example, something that say analyzed source files and found things like undeclared variables or a js file of defined type objects like int or string?

In addition to JSLint, Google Closure Compiler can be used for static analysis of JS source as well, and it checks different things than JSLint too.

Neither of these tools does provide exactly what you want though.. Closure Compiler attempts type-checking if I remember correctly, but it doesn't always work (at all).

Although such features may seem desirable from the point of view of someone who's used to strictly typed languages, I often see people attempting to use JS like C#/Java/whatever go wrong on more than one level, and usually ending up with less readable and worse code in general. Of course this may not be your case, but this is just a general observation/warning to keep in mind.

My suggestion would be to embrace the "looseness" of the language, with perhaps test-driven development as a quality assistance tool (JsTestDriver).

You want a lint program. Try jslint -- http://www.jslint.com/

Like @no said, jslint is hawt . I think you're looking for the Closure compiler , though.

If you want to check the javascript dependencies and define a client-side architecture, you can use JSAnalyse .

It allows you to keep the dependencies between javascript files under control by checking it during the build. It extends the Visual Studio Layer Diagram to support javascripts and can be easily integrated into the msbuild process.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM