Revision 2.53 of API v2

Friday, June 02, 2006 at 2:43:00 PM

This week there's one API bugfix: the GOverviewMapControl no longer covers the copyright.

Here's an interesting Javascript story from a bug I ran into last week. There was an API site missing copyrights, and I tracked it down to a part of GCopyrightControl I had worked on that had code like this:

copyrightObject = {};
copyrightObject[somePrefix] = someArray;

for (var prefix in copyrightObject) {
  copyrightText += copyrightObject[prefix].join(', ');
}

But there was an exception saying "copyrightObject[prefix] is not an array" even though the only values I set on it were arrays. How could that be? It turned out the site had a library that modified Object.prototype, so when I wrote {}, I was not getting a blank object at all, but one with existing properties. I was treating copyrightObject as an empty hash table, but it didn't start empty.

What's the fix? First I used .hasOwnProperty() to ignore inherited properties. That looked good until our testing team caught a bug in the bugfix on its way to production: Safari 1.3 doesn't support hasOwnProperty. Ahh, browser compatibility fun! So in the end, I kept a separate array of the prefixes. Lesson of the week: Javascript objects are not quite hash tables.

API v1 Current: 1.31
API v1 Default: 1.31
API v2 Current: 2.53
API v2 Default: 2.52