08 Apr 2008

On my website, I have a widget showing the articles I had recently starred with Google Reader. That widget  stopped appearing recently. After some research, I found out that  the javascript error  "opera.version is not a function" is caused by my scripts initialising a variable with the name "opera" (thanks to David Buchmann for his writeup).

You see, to render nicely in Opera, the Google javascript wants to work with a variable by that name. If it runs in an Opera browser, Opera will provide that variable. If not, it should be "undefined" because it doesn't exist. Unless, of course,  my script (or any other that ran before) instantiated a javascript variable "opera".

Well, my scripts did (it's a natural variable name to come up with if you want to store somewhere that the browser is/is not an Opera browser). I renamed that variable and the Google Reader items show up again.

Here, we have a nice first-hand experience why namespaces are a great idea. But as the web grows in an organic manner, we have to take what is there.

Lessons learned?

  • Name variables in your code more specific than general. For instance, isOpera would have been better than opera.
  • When there are no namespaces defined, the big eat the small. If your script is less important than, say, Operas or Googles, then watch the hell where you're naming, little guy.
# lastedited 08 Apr 2008
You are seeing a selection of all entries on this page. See all there are.