About Me

My name is Mikael Eliasson. I'm a 24 year old orienteerer, runner and programmer who lives in Gothenburg, Sweden and study Software Engineering at Chalmers university. I will write about programming, training and maybe some other stuff too.

Follow me


Hey, get in line

Today when I was applying the module pattern in my javascript I got an error saying "invalid label" in Firebug.

Sometimes habits from different languages work lovely toghether but there are times when these habits causes you code to go haywire. My last run-in with on of these habits happend when I was trying to add a global javascript file to one of my sites. To make sure I wouldn't polute the global namespace (read why here or just google it) I was applying the module pattern. Now to my suprise it wasn't working. It said my namespace was not defined and because it wasn't my first time doing this I got pretty suprised. At the time I only had one method and I didn't have the energy to investigate it so I dropped the code directly into global namespace instead.

Today I had the need to add more methods so I came back to this file. After adding my methods and updating the return statement it looked like this:

        initMenu: initMenu,
        showValidationErrors : showValidationErrors,
        getValidationErrorDOM : getValidationErrorDOM

Now that looked just great to me but when I ran the site I got the following error in firebug:

invalid label at the row showValidationErrors : showValidationErrors

After a while I remebered that in Javascript you want to place your leading curly brace on the end of the line and not on the next line. So I changed my code to:

        initMenu: initMenu,
        showValidationErrors : showValidationErrors,
        getValidationErrorDOM : getValidationErrorDOM

And everything worked just great again. The reason for this is that javascript automatically adds semicolons to some statements if there is none. And because return; certainly would be valid I guess that is what happend to me.


  • krishna 30 aug 10:14 2011
    Thank you. You saved my day.

Add a new comment

WSW33 - IUSR_689 -