Ali was working on an app for a national government. The government provided its own mapping API for its own custom mapping services. It did not provide any documentation, and the only "sample" code was hitting "view source" on an existing map page on the government's websites.

Ali writes: "I was going through their own implementations, looking for something that would help, when I stumbled upon this gem. I think it speaks for itself, no?"

var mapType; var mapURL; function addMapService(type,url) { mapType = type; mapURL = url; performAdd(); } function performAdd() { try { setTimeout("index.addMapService(mapType,mapURL);",2000); } catch(err) { if(err.name=="TypeError") performAdd(); } }

No, Ali, this absolutely does not speak for itself, because I have a lot of questions. So many questions.

addMapService populates some global variables and then calls performAdd, because gods forbid that we pass parameters. performAdd passing a string of JavaScript code, which invokes index.addMapService and passes the global variables, and schedules that execution for two seconds in the future.

Why? I've heard of lazy loading, but this is a bit ridiculous.

Now, it's important to note that setTimeout couldn't possibly throw an exception in this example, but it's okay, because if it does for some reason, we'll… just do the same thing. I guess with another two second delay. And since we're using global variables, I guess maybe the value could change before this code executes, so retrying the same action time and time again until it works… might actually work. It probably won't do what you expect, but it'll do something.

So no, I don't think this speaks for itself, and honestly, whatever it's trying to say, I wish it would stop.

[Advertisement] ProGet’s got you covered with security and access controls on your NuGet feeds. Learn more.