So all of a sudden, the AddThis button starts giving a mysterious javascript error on all of our CFS Website Service sites. It went from working perfectly to throwing an error, without any change to any of our code. When I would mouseover the AddThis button, firebug would display the following error: “addthis_efrom is not defined”. So I poked into the AddThis javascript code and found the particular line that was giving the problem:
s += efr("at_from",
w.lang(al,8),
_117,
0,
(addthis_do_ab||window.dbg?addthis_efrom:"")
);
If firebug is telling me that addthis_efrom is not defined, then that must mean that window.dbg is defined. There are no other references to addthis_efrom and only one other similar reference to window.dbg in the AddThis code. I assume it’s something they use for debugging and then remove when they push their code live. There’s no definition for window.dbg anywhere in the AddThis code — that I can find. From the looks of the code and the fact that addthis_efrom variable isn’t defined, it appears that they’re no expecting window.dbg to be defined in the live environment.
I start looking through our javascript code — a convaluted pot that has had many fingers in it over the years — and find the culprit. A single line in one of our javascript files:
dbg = function() { return false; }
At some point, someone on our end created a function called dbg. Just so happens that at AddThis used that same variable name. Great. Tons of hassle and wasted time for such a trivial issue. I’m actually quite surprised that AddThis wouldn’t implement at least some manner of namespacing their variables, just to ensure that this kind of issue wouldn’t arise. Aside from maybe that variable name “debug”, I wouldn’t be surprised to find that a lot of people out there are using “dbg”. All that the developers at AddThis needed to do in order to avoid this hassle, would have been to either wrap their dbg variable in an object, to act as a pseudo-namespace, or even something as simple as prefacing their variables, something like: addthis_dbg or even at_dbg. Then again, maybe there is some reason that they chose to use dbg that I’m just unaware of. If nothing else, I’ll give them the benefit of the doubt…
I guess you could flip the coin and say that the onus is on us to namespace our own variables. That just doesn’t sit well with me. AddThis wants us to use their button, so they should be concerned with ensuring that their code won’t conflict with ours in anyway. No one is going to use a third party solution if it breaks their existing code base. At the end of the day, all of our debugging code that uses the dbg() function has to be changed in order to accomodate the AddThis button. Which isn’t much more than stress and hassle for us and our clients.