Inigo Montoya: Javascript Guru

Ovid on 2005-10-21T22:31:26

Inigo Montoya: "You keep using that JavaScript. I do not think it means what you think it means."


  
    
  
  
    
  

That should pop up two alerts. The first says the value is 21. The second alert says the value is 18. That took me quite a while to debug.

In other news, Javascript is a neat language. It's debugging facilities, however, are even worse than Perl's.

By the way, how do I tell if a given element is an array (as in "age" above) or a single value (as in "one_value" above)? I can't seem to figure that out. I can get it working if I try to use the darned thing as an array and then catch the exception when it fails, but that's awful :(

Update: the problem is solved with this function:

      function elemIsArray(elem) {
        var string = Object.prototype.toString.apply(elem);
        var name = string.substring(8, string.length - 1);
        return (name.match(/nodelist/i) != null);
      }


Who needs debugging?

ferreira on 2005-10-21T22:56:32

The trick is not making errors. In this case, why would you need those horrible creatures called debuggers? Well, you have a problem if, unlike me, you don't keep writing a maximum of 25 lines of code.

Re:Who needs debugging?

Ovid on 2005-10-21T23:06:52

Not make errors? Silly me. Why didn't I think of that?