n

Archive

Opera and the variable scope chain

Today I recieved a mail from Dunstan, who, in his turn, recieved a mail from somebody else who noticed yet another bug in NiceTitles. I don't recall how that bug got back in, but it did. What was the problem, and in what way does it relate to the title of this entry?

Because NiceTitles supports XML documents and uses a template string, the output string must be converted into XML. This is done through the DOMParser. As Opera - as version 7.2x and below - does not support JavaScript in an XML document, it does not have DOMParser (I think it will need it, when it support JavaScript in XML documents. The same counts for things as document.createElementNS).

The if statement used to verify the existance of document.createElementNS and DOMParser looks like this: if(document.createElementNS && DOMParser) This should give no problems. From the current variable scope chain the JavaScript interpreter goes up until if finds the operands (or not). In Mozilla, it'll find the operands in the window scope. In Opera this works as expected for document.createElementNS, however DOMParser throws an error. Opera states that the variable is not defined. Instead of going up the variable scope chain, it stops at the lowest scope, finding nothing. However, when you use window.DOMParser it's all fine with Opera.

I find this behaviour very confusing. It's definately something to remember. NiceTitles have again been updated, and the bug is gone now. At the end of the day, I (we) learned another new lesson and NiceTitles functions even better.

Comments

  1. Dunstan wrote:

    Mark - as always I’m thoroughly impressed with the speed of your response to the bug, and your JS ability.

    I see on lots of sites people are saying “This year I must learn a new langauge”, I think my choice is going to be JS. An odd choice, maybe, but I really like the way JS can add the finishing touches to a site.

    You and Stuart over at http://www.kryogenix.org/ have inspired me to get better at it… if only so I don’t have to bother you both each time I run into a problem ;o)

    Thanks for the fix.

    January 11, 2004 @ 2:18 pm. Type: Comment. Permalink.

  2. Mark wrote:

    “Mark - as always I’m thoroughly impressed with the speed of your response to the bug, and your JS ability.”
    I just happen to have some time on my hands, and the bugs are most of the time easily fixed. But, of course, thanks for the compliment :)

    “I think my choice is going to be JS.”
    JavaScript is easily underestimated. Just like any other weblanguage, I guess. If you are going to learn JavaScript this year, I wish you a lot of luck. Make sure to get “JavaScript - The Definitive Guide, 4th edition”, by David Flanagan. It’s a great resource, and David explains things well.

    “You and Stuart over at http://www.kryogenix.org/ have inspired me to get better at it… if only so I don’t have to bother you both each time I run into a problem ;o)”
    Good to hear that (mostly the former, not the latter). If you got any questions, I’d like to help out.

    January 11, 2004 @ 3:01 pm. Type: Comment. Permalink.

Leave a Comment

Due to some recent spam, and because this site is no longer active I've decided to disable comments side-wide. You can always mail me if you have questions. Thanks!


Navigate


Colophon

Hey! I'd like you to know that this site will be gone soon. Problems with this site (which never was intented as a final release, but has been active for some months already now) will not be solved, sorry for any inconvenience.

The future address of the new site will be http://novemberborn.net/

Summary

Oops, there is no summary.

Context


Misc.

Copyright 2003 - 2004 Mark Wubben. This website is licensed under a Creative Commons License. Powered by WordPress