Poor use of parenthesis positioning when creating statements
You should always put a bracket after the instruction because of the automatic insertion of a semicolon.
For example:
function() { return { price: 10 } }
very different from this:
function(){ return{ price: 10 } }
Becuase in the first example, javascript inserts a semicolon for you, actually leaving you with this:
function() { return;
Using setInterval for potentially lengthy tasks.
You should use setTimeout instead of setInterval for cases when you need to do something repeatedly.
If you use setInterval, but the function that runs in the timer is not complete by the time the next timer ends, this is bad. Use the following template instead using setTimeout
function doThisManyTimes(){ alert("It happening again!"); } (function repeat(){ doThisManyTimes(); setTimeout(repeat, 500); })();
This is very well explained by Paul Irish on his 10 things I learned from the jQuery video source.
Swaff Mar 31 '11 at 20:51 2011-03-31 20:51
source share