3 ms·
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>
by heyrhett 15y 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>
- pdenya 15y agoJavascript 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.