Chris Wetherell Since October 5, 2000
Massless

July 2004

What's In A Name? An Object Property.

This post about namespace collisions in Javascript at the Marius Weblog outlines, in part, a technique I've also been using for some time and which is a keeper, I think, for those of us writing large libraries in Javascript.

Large libraries with sensible naming conventions will find themselves somewhat hampered as unique function names that can be widely appropriate will get snatched up. In order to avoid namespace collision then, I (and Marius, it seems) will create a user-defined object that stores methods and element IDs.
function Posting() {}

Posting.SAVE_BUTTON_ID = "Save";

Posting.Save = function()
{
...code does something...
}
and so forth...