JavaScript Double Dollar Sign

后端 未结 5 2159
别那么骄傲
别那么骄傲 2020-11-29 06:54

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 i

相关标签:
5条回答
  • 2020-11-29 07:37

    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. ;)

    0 讨论(0)
  • 2020-11-29 07:38

    As far as I know, the dollar sign is just a regular character that can be used in variable names. It could be a convention to signify a property that shouldn't be messed around with.

    My guess is that the author used $$guid to avoid clashing with existing property names. He could probably have used __guid or something similar instead.

    0 讨论(0)
  • 2020-11-29 07:39

    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.

    0 讨论(0)
  • 2020-11-29 07:50

    Double dollar sign is referenced in the following terms -

    //getElementById    
      function $$(id){
        return document.getElementById(id);
      }
    
    0 讨论(0)
  • 2020-11-29 07:52

    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.

    0 讨论(0)
提交回复
热议问题