javascript

I’m not, really. Still I’ve been debugging some JS code just to remember why I was not so excited in the past about the language: your code needs to cope with browser specific crap.

Now, are you good at Javascript? If so, without running it, have a look at the following code:

var array = [
    {
        key : 'value',
        foo : 'bar'
    },
    {
        key : 'eulav',
        foo : 'rab'
    },
];

for (var i = 0 ; i < array.length ; i++)
{
    console.log ("key -> " + array[i].key);
    console.log ("foo -> " + array[i].foo);
}

How many elements does the array variable holds?

That code actually hides an Evil™ syntax detail I discovered today. Now, since I’ve been recently approached by the viral ideas of somebody, I felt compelled to fully understand the above code (and the bug we worked together from which this example came out). So if you really want some hints about what the hell is this all about:

  • if you’re not running Microsoft IE7, chances are you’re not going to see anything weird in the console output :P
  • section 11.1.4 of the ECMAScript v3 spec tells you all you need to know about the array initializers

After all, I’ll be probably continuing to study this “suddenly-a-hot-chick” Javascript thing, hoping to find a better world where my eventual code will be living into than that I found in the old days.

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)