The dollar function must die
Entry created on Thursday 19 February 2009 at 15:06.
A number of JavaScript libraries have a function called $ and I’m irritated by it for a number of reasons:
-
The dollar sign is intended for use only in mechanically generated code.
… which the libraries are not.
The name doesn’t give a clue as to what the function does or where maintainers should look for documentation.
Different libraries use the
$function to do different things. In Prototype.js it means “Get the element with this id”, but in jQuery is means “Get all the elements that match this CSS selector”. Maintainers have to know what library is in use to know what the function does and can’t easily tell by just looking at the code.
If you have a library with a $ function, please don’t use it. Good libraries have alternatives (such as jQuery) or don’t create the function at all (such as YUI).
Comment on this entry.
