JS Lint, how semantic does Javascript have to be?
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 confor开发者_Go百科ming to JS Lint semantics and syntax?
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.
精彩评论