Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does a $ in a javascript function name mean?

Tags:

javascript

GWT outputs codes like this:

function com_mycompany_mywebapp_client_CTest_$$init__Lcom_mycompany_mywebapp_client_CTest_2V(){
this$static}

What does the $ mean, or is it just another character like an underscore? Would this_static mean the same thing?

like image 755
dan gibson Avatar asked Dec 29 '22 01:12

dan gibson


2 Answers

Nuthin. It's just a character. Think of it as an S with a stick stuck through it.

like image 198
bmargulies Avatar answered Jan 09 '23 11:01

bmargulies


The dollar sign was added to be used for machine-generated symbols so they wouldn't collide with manually written symbols. But syntactically it's just like underscore, it doesn't mean anything special.

When people discovered they could use just $() as a function name, they started to use it as a shortcut for document.getElementById() and different people extended it in different directions. Now it is often used in libraries and frameworks like Prototype or jQuery which both use $() functions in their own way (that's why you have to use jQuery.noConflict() to use both Prototype and jQuery in the same page). The dollar sign is often used in front of variable names to remember that it's a jQuery object, like this:

var $links = $('a');

But some people don't like it being used that way - eg. see the Code Conventions for the JavaScript Programming Language by Douglas Crockford.

like image 42
rsp Avatar answered Jan 09 '23 10:01

rsp