Hacker News new | ask | show | jobs
by heyrhett 5469 days ago
I'll use anything that fixes the way javascript handles scoping. Take this gem, for example:

<html> <body> <ul> <li>First</li> <li>Second</li> <li>Third</li> <li>Fourth</li> </ul> </body>

<script type="text/javascript"> els = document.getElementsByTagName('li'); for(i=0; i < els.length; i++){ els[i].addEventListener('click', function(){alert(i);}, false); } </script> </html>

1 comments

Javascript has a few gotchas like this one. These are annoying for people new to the language but after knowing they exist they're easily avoided.