Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <hr> <pre><code>(function( $ ){ })( jQuery ); </code></pre> <p>That is self-executing anonymous function that uses <code>$</code> in argument so that you can use it (<code>$</code>) instead of <code>jQuery</code> inside that function and without the fear of conflicting with other libraries because in other libraries too <code>$</code> has special meaning. That pattern is especially useful when writing jQuery plugins.</p> <p>You can write any character there instead of <code>$</code> too:</p> <pre><code>(function(j){ // can do something like j.fn.function_name = function(x){}; })(jQuery); </code></pre> <p>Here <code>j</code> will automatically catch up jQuery specified at the end <code>(jQuery)</code>. Or you can leave out the argument completely but then you will have to use <code>jQuery</code> keyword all around instead of <code>$</code> with no fear of collision still. So <code>$</code> is wrapped in the argument for short-hand so that you can write <code>$</code> instead of <code>jQuery</code> all around inside that function.</p> <p>If you even look at the source code of jQuery, you will see that everything is wrapped in between:</p> <pre><code>(function( window, undefined ) { // jQuery code })(window); </code></pre> <p>That is as can be seen also a self-executing anonymous function with arguments. A <code>window</code> (and <code>undefined</code>) argument is created and is mapped with global <code>window</code> object at the bottom <code>(window)</code>. This is popular pattern these days and has little speed gain because here <code>window</code> is will be looked into from the argument rather than global <code>window</code> object which is mapped below.</p> <hr> <p>The <code>$.fn</code> is jQuery's object where you create your new function (which is also an object) or the plugin itself so that jQuery wraps your plugin in its <code>$.fn</code> object and make it available.</p> <hr> <p>Interestingly, I had answered similar question here:</p> <p><a href="https://stackoverflow.com/questions/4472528/javascript-jquery-closure-function-syntax">JavaScript / jQuery closure function syntax</a></p> <p>You can also check out this article to know more about self-executing functions that I had written:</p> <p><a href="http://webupon.com/audio/javascript-self-executing-functions/" rel="nofollow noreferrer">Javascript Self-executing Functions</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload