Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "$.something" mean in jquery?

Tags:

jquery

i find it everywhere, like this.

function($) {
  $.test = { some code }
}

what does it mean?

like image 285
Capi Etheriel Avatar asked Jan 29 '11 23:01

Capi Etheriel


1 Answers

Think of $ just like any other variable. For jQuery, it's the jQuery object, which is pretty powerful. But it's just like any other variable; you could write your own $ if you wanted to, for example.

It's an unusual variable name, yes, but there's nothing magical about it. The .something is just a property of the variable $. It's no different than writing obj.something, except the variable name is $ instead.

The other non-alphanumeric character you can use in JavaScript as a variable name is _ (the underscore). It's used in some other libraries, like underscore.js . But again, there's nothing special about using _.

like image 175
Reid Avatar answered Nov 09 '22 16:11

Reid