locked
Variable scoping in Bing Maps javascript (mapcontrol.ashx v6.2) RRS feed

  • Question

  • I have been working on the Bing Maps browser plugin extensively for the last 9 months. While working on the current project, I found that somewhere in the mapcontrol.ashx(v6.2) the javascript code was throwing an exception. The line was 129 and the character was 372391and the exception was "Function expected". Debugging to the point of the exception was useless, since the mapcontrol was obfuscated and we could not figure out what was wrong. After spending 2 days with the issue, we figured out that javascript was using calling a function b() which is obviously obfuscated. there was another script on the same page (from another program, not mapcontrol) which was using the variable b. They were clashing with each other and bing map's variable was getting overwritten by the other script. There was no way we could fix it, since we had no control over either bing maps javascript or the other script. This is a result of not scoping the variables properly. if the maps API had scoped the b function properly, the JS engine would not have overwritten it and things would be fine.
    So my message to the Bing Maps team, either don't obfuscate your code or give proper scoping to the variables and functions. This is a great product and I would hate it to be peppered with issues which can easily fixed.
    Tuesday, July 21, 2009 10:33 PM

Answers

  • This issue has come up a number of times and has been raised with the proper team at MSFT. As a tip for debugging the mapcontrol, download a local copy and run it through a code beautifier. This will somewhat un-obfuscate the code and make it easier to track down bugs. I do this all the time when I'm having a hard time locating my issue. As a bonus, if your using firebug you can easily set up break points and step through the code to see how things work.

    Windows Live Developer MVP - http://rbrundritt.spaces.live.com
    Sunday, November 29, 2009 11:48 AM
    Moderator