JS Lint,Javascript 的语义必须如何?

发布于 2024-10-10 20:49:17 字数 232 浏览 5 评论 0原文

所以 JSLint 是一个提升语义和语法的漂亮工具。我从客户站点获取到 JS Lint 的大多数 JS 通常会失败,尽管它们会吱吱作响,并且大多数站点功能仍然有效。我试图向他们推销修复他们的 Javascript,但他们认为它没有损坏(意味着它正在做他们想要做的事情)为什么要修复它?语义和语法对他们来说太抽象了。

您认为,使用 JS 的网站必须遵守 JS Lint 代码标准有多重要?符合 JS Lint 语义和语法的好论据是什么?

So JSLint is a nifty tool which promotes semantics and syntax. Most JS that I get from client's sites into JS Lint usually fails though they squeak by and most of the sites functionality still works. I try to sell them on fixing their Javascript but they see it as if it ain't broke ( meaning it is doing what they want it to do ) why fix it? Semantics and syntax is too abstract for them.

In your opinion, how important do sites with JS have to adhere to JS Lint code standards? What is a good argument for conforming to JS Lint semantics and syntax?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

思慕 2024-10-17 20:49:17

我会举一些常见的 javascript 陷阱的例子。可能会导致维护期间需要更多时间进行调试。
全局变量:

function doStuff(param1, param2) {
    foo = var1 + var2;
    return foo;
}

括号和缩进:

// our friend 'foo' from above. this might pass because it was global.
// what if the original writer expected foo to be undefined?
if (foo)
    foo += "some string"; // this is inside the condition
    foo += "some other string"; // this is outside. but it's not immediately obvious!

还有更糟糕的例子。去找一些非常令人讨厌和混乱的代码,然后根据 jslint 修复它,并比较两个片段。你的卖点是干净代码的维护成本远低于维护脏代码的成本。

I would give some examples of common javascript pitfalls. Ones that could lead to more time debugging during maintenance.
Global variables:

function doStuff(param1, param2) {
    foo = var1 + var2;
    return foo;
}

Brackets and indentation:

// our friend 'foo' from above. this might pass because it was global.
// what if the original writer expected foo to be undefined?
if (foo)
    foo += "some string"; // this is inside the condition
    foo += "some other string"; // this is outside. but it's not immediately obvious!

There are much worse examples out there. Go find some really nasty and confusing code, then fix it according to jslint, and compare the two snippets. Your sell will be that maintenance cost of clean code is much less than the cost of maintaining dirty code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文