Why are Javascript for/in loops so verbose?

Posted by Matthew Scharley on Programmers See other posts from Programmers or by Matthew Scharley
Published on 2011-02-16T00:43:13Z Indexed on 2011/02/16 7:33 UTC
Read the original article Hit count: 329

Filed under:
|

I'm trying to understand the reasoning behind why the language designers would make the for (.. in ..) loops so verbose. For example:

for (var x in Drupal.settings.module.stuff) {
    alert("Index: " + x + "\nValue: " + Drupal.settings.module.stuff[x]);
}

It makes trying to loop over anything semi-complex like the above a real pain as you either have to alias the value locally inside the loop yourself, or deal with long access calls. This is especially painful if you have two to three nested loops.

I'm assuming there is a reason why they would do things this way, but I'm struggling with the reasoning.

© Programmers or respective owner

Related posts about JavaScript

Related posts about language-design