Understanding a skelton of jQuery plugin

Posted by TK on Stack Overflow See other posts from Stack Overflow or by TK
Published on 2010-03-17T09:28:21Z Indexed on 2010/03/17 9:31 UTC
Read the original article Hit count: 284

Filed under:
|
|

At a website, I found the following code to make a jQuery plugin:

(function($){
  // Our code here...
})(jQuery);

I don't understand how the code above works. What I understand is that the code executes immediately because the very last () in function(){}(). So the entire code says that is an anonymous function that is run immediately.

But I don't understand why the wrapping needs to pass jQuery and that inside it needs $ to be passed.

From my understanding, $ is an alias to jQuery, meaning practically the same. What is the meaning of $ and jQuery here? How does the overall code work as a jQuery plugin?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery