Don’t make an ASS of U and ME

published on
February 20th, 2009
by fry

What’s wrong with the following line of code (from WordPress 2.6.5, common.js)?

jQuery(function(){jQuery('#media-buttons a').tTips();});

What guarantees do you have that by the time the internal function executes the global jQuery will still be the one you expect it to be or that it will have the tTips plug-in you attached a few lines earlier? Nothing. You just ASSUME it will be. You didn’t put it there, so you can be sure that nobody will. Right.

jQuery developers knew this might be a problem so jQuery will pass a reference to the itself as an argument when triggering this event:

jQuery(function($){$('#media-buttons a').tTips();});

This would work and wouldn’t break. And it would make your platform a bit more hackable.

Express your opinion

My name is Marko Mrdjenovič and I’m a web developer and a manager from Ljubljana, Slovenia (N 46° 03.246,W 14° 30.265).

I work at Zemanta, I’m a WaSP ILG member and I’m also the program lead at local weekly talks Spletne urice / www:h.

Blog archive

Advertisments

Jobs

Come in, we're hiring

Full-time and freelance job opportunities available at Authentic Jobs:

  • Loading ...

Post a job and reach web professionals everywhere.