Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does $$ mean in Javascript?

I am looking at some javascript code and it has this in a function:

$$('.CssClass').each(function(x) { .... } )

I get that the intent is to apply the anonymous function to each element with a class of CssClass, but I can't work what the $$ refers to ... and can't google for $$!

Update: thanks for the hints. The javascript comes from the iPhone look-alike library: jPint which includes the prototypejs library, and does define $$ as:

function $$() {
  return Selector.findChildElements(document, $A(arguments));
}
like image 929
Rob Walker Avatar asked Nov 28 '22 13:11

Rob Walker


2 Answers

Probably this prototype function:

$$(cssRule...) -> [HTMLElement...]

Takes an arbitrary number of CSS selectors (strings) and returns a document-order array of extended DOM elements that match any of them.

http://www.prototypejs.org/api/utility#method-$$

like image 191
Tom Haigh Avatar answered Dec 09 '22 22:12

Tom Haigh


$ is an ordinary symbol character, thus "$", "$$", "$$$" are ordinary variables.

the meaning of $ depends upon the libraries that are in use; in jQuery the $-function creates a jquery object from a css selector, e.g. $("DIV") is a collection of all DIVs in the current document.

like image 23
mfx Avatar answered Dec 09 '22 21:12

mfx