开发者

What does a $ in a javascript function name mean?

开发者 https://www.devze.com 2023-02-11 14:02 出处:网络
GWT outputs codes like this: function com_mycompany_mywebapp_client_CTest_$$ini开发者_开发技巧t__Lcom_mycompany_mywebapp_client_CTest_2V(){

GWT outputs codes like this:

function com_mycompany_mywebapp_client_CTest_$$ini开发者_开发技巧t__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?


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号