Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
58
rated 0 times [  61] [ 3]  / answers: 1 / hits: 53160  / 14 Years ago, tue, june 8, 2010, 12:00:00

What is the best practice for that then?



Jslint explains that it adds confusion. I don't see it really...



EDIT: The code, as requested:



  var all,l,elements,e;
all = inElement.getElementsByTagName('*');
l = all.length;
elements = [];
for (e = 0; e < l; (e++))
{
if (findIn)
{
if (all[e].className.indexOf(className) > 0)
{
elements[elements.length] = all[e];
}
} else {
if (all[e].className === className)
{
elements[elements.length] = all[e];
}
}
}

More From » jslint

 Answers
8

The longstanding best practice: use i += 1 instead, following jslint's advice.


As for why it is a better practice than ++, according to Crockford:



The increment ++ and decrement -- operators make it possible to write in an extremely terse style. In languages such as C, they made it possible to write one-liners that: for (p = src, q = dest; !*p; p++, q++) *q = *p; Most of the buffer overrun bugs that created terrible security vulnerabilities were due to code like this. In my own practice, I observed that when I used ++ and --, my code tended to be too tight, too tricky, too cryptic. So, as a matter of discipline, I don’t use them any more.



Edit: Included comment from Nope as this answer continues to get views.


[#96560] Friday, June 4, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ervindouglasm

Total Points: 451
Total Questions: 103
Total Answers: 102

Location: Turkmenistan
Member since Thu, Dec 1, 2022
1 Year ago
;