简体   繁体   English

Javascript代码分析和最佳实践

[英]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? 是否有任何工具可以帮助程序员真正想要类型安全和更严格的c#或java等语言规则?

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? 例如,某些东西说分析了源文件并找到了未声明的变量或定义类型对象的js文件,比如int或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. 除了JSLint之外,Google Closure Compiler也可以用于JS源代码的静态分析,它也可以检查与JSLint不同的东西。

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). 这些工具都没有提供你想要的确切内容。如果我没记错的话,Closure Compiler会尝试进行类型检查,但它并不总是有效(根本没有)。

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. 虽然从习惯严格键入语言的人的角度看这些功能似乎是可取的,但我经常看到人们尝试使用JS,如C#/ Java /在多个级别上出错,并且通常最终会降低可读性更糟糕的代码。 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). 我的建议是接受语言的“松散”,也许将测试驱动的开发作为一种质量辅助工具(JsTestDriver)。

You want a lint program. 你想要一个lint程序。 Try jslint -- http://www.jslint.com/ 试试jslint - http://www.jslint.com/

Like @no said, jslint is hawt . 就像@no说的那样,jslint是hawt I think you're looking for the Closure compiler , though. 不过,我认为你正在寻找Closure编译器

If you want to check the javascript dependencies and define a client-side architecture, you can use JSAnalyse . 如果要检查javascript依赖关系并定义客户端体系结构,可以使用JSAnalyse

It allows you to keep the dependencies between javascript files under control by checking it during the build. 它允许您通过在构建期间检查javascript文件来控制javascript文件之间的依赖关系。 It extends the Visual Studio Layer Diagram to support javascripts and can be easily integrated into the msbuild process. 它扩展了Visual Studio Layer Diagram以支持javascripts,并且可以轻松集成到msbuild进程中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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