Wednesday, April 25th, 2007
Seven JavaScript Techniques You Should Be Using Today
Dustin Diaz has written an article on the Seven JavaScript Techniques You Should Be Using Today.
Dustin delves into:
- Branch when possible: When performance matters, it’s often advisable to branch out your functions in a way that ensures processor-intensive or memory-hungry tasks won’t be frequently repeated. One of the most common scenarios where this situation can arise is handling browser differences
- Make Flags: var w3 = !!(document.getElementById && document.createElement); The not operators (!!) simply perform a Boolean conversion. The first operator changes the type of the object on the right to a Boolean, and then the second will just reverse whatever the first returned
- Make bridges: function getUserNameByIdBridge (e) { getUserNameById(e.id); }
- Try Event Delegation: Read Christian Heilmann’s work
- Include methods with your getElementsByWhatever: Use callbacks. getElementsBySelector(‘#example p a’, function(el) {}
- Encapsulate your code:
(function() { ..... })();





3.1 rating from 40 votes
6 != 7 :)
Good stuff though.
I guess re-inventing the wheel doesn’t get a look in on this website ;)