Reputation: 113
Please explain the meaning of the $ and $$
This is sample code use $ and $$: https://github.com/cytoscape/cytoscape.js-qtip/blob/master/cytoscape-qtip.js
what mean this code use $:
var $qtipContainer = $('<div></div>');
Upvotes: 8
Views: 31750
Reputation: 1
In the browser developer tools console - at least in Firefox, IE11, (can't test lesser IE's), Edge and Chrome - $
and $$
do have particular functions (if the page hasn't defined those vars) - see MDN Documentation for helper commands in the Web Console Helpers.
Upvotes: 6
Reputation: 214
If you are using prototype javascript then $$() & $() are selectors. For more information visit https://www.tutorialspoint.com/prototype/prototype_utility_methods.htm
Upvotes: 0
Reputation: 587
It's a naming convention in JavaScript for variables that store JavaScript objects. Their name should start with $
. Exactly like in your example:
var $qtipContainer = $('<div></div>');
Because JavaScript is untyped language, this is useful way for programmers to distinguish whether variable stores jQuery object or for example DOM object.
Upvotes: 3
Reputation: 31467
$
and $$
are valid variable names in JavaScript, they have no special meaning.
Usually they set their value to library instances, in your example if you check the closure call, at the end of the file you'll see that $
is jQuery in this case if it is defined and $$
is cytoscape.
See the corresponding code part:
;(function( $, $$ ){ 'use strict';
// ...
})(
typeof jQuery !== 'undefined' ? jQuery : null,
typeof cytoscape !== 'undefined' ? cytoscape : null
);
Upvotes: 3
Reputation: 1346
Referring to the source code, $
is jQuery, and $$
is cytoscape.
Besides, the $
symbol is perfectly valid variable name.
Upvotes: 2
Reputation: 340
$ sign is a valid identifier in JavaScript. $$ was a notation that used back when packer was popular but no significance now.
Upvotes: 0
Reputation: 21492
The whole code is just a function call with two arguments:
;(function( $, $$ ){ 'use strict';
// skipped
})(
typeof jQuery !== 'undefined' ? jQuery : null,
typeof cytoscape !== 'undefined' ? cytoscape : null
);
The first argument is jQuery
global variable (or null
, if jQuery
is undefined), and the second is cytoscape
global variable (or null
, if is undefined).
Upvotes: 8