JavaScript Double Dollar Sign

I understand the use of the (single) dollar sign in popular JavaScript libraries such as jQuery and Prototype. I also understand the significance of the double dollar sign in PHP (variable variables). Dean Edwards uses the double dollar sign in his famous addEvent() JavaScript function. Here is an except containing the use of the double dollar sign:

function addEvent(element, type, handler) {
  // assign each event handler a unique ID
  if (!handler.$$guid) handler.$$guid = addEvent.guid++;
  // create a hash table of event types for the element
  if (!element.events) element.events = {};
  // create a hash table of event handlers for each element/event pair
  var handlers = element.events[type];
  if (!handlers) {
    handlers = element.events[type] = {};
    // store the existing event handler (if there is one)
    if (element["on" + type]) {
      handlers[0] = element["on" + type];
    }
  }
  // store the event handler in the hash table
  handlers[handler.$$guid] = handler;
  // assign a global event handler to do all the work
  element["on" + type] = handleEvent;
};
// a counter used to create unique IDs
addEvent.guid = 1;

From what I've read, the dollar sign only officially has significance in JavaScript for code generation tools, although that standard is largely ignored today due to the dollar signs widespread usage in the aforementioned JavaScript libraries.

Can anyone shed any light on this usage of the double dollar sign in JavaScript?

Thanks very much!


I wrote this function. :)

There is no longer any special significance to the $$ prefixes. It was a notation that I used back when packer was popular. Packer would shorten variable names with this prefix. Nowadays Packer will automatically shorten variable names so this notation is redundant.

Short answer, the $ sign is a valid identifier in JavaScript so you are just looking at a bunch of ugly variable names. ;)


Well really, it's just the naming convention of the developer. "$$" might as well as be "aa", for all intents and purposes.

As you mentioned, the single dollar sign function $() has become almost-standard in various JavaScript libraries. "The one function to rule them all", eh? But remember, it's nothing inherent to JS itself. It's just a function name that caught on to replace document.getElementById().

So, with that said, $$ could be anything. Heck, you could even have a function like this:

function $$$$$$$$(){
  //i've got dollar signs in my eyes!
}

In other words, it's just a variable/function name—just like all the rest.


Just as others have said, $$ is an arbitrary identifier.

The JavaScript toolkit MochiKit reserves a function identified by the same to select elements using CSS selector syntax, much like jQuery does, except without wrapping all the matching elements in a special object.

So, yeah - it's nothing particularly special, in and of itself.