Note that there are some explanatory texts on larger screens.

plurals
  1. POUnderstanding JavaScript functions and plugins set up
    primarykey
    data
    text
    <p>I have just started to write JavaScript after some time and I am confused by plugins constructor set up. I went through this link for advice.</p> <p><a href="https://stackoverflow.com/questions/3755606/what-does-the-exclamation-mark-do-before-the-function">What does the exclamation mark do before the function?</a></p> <p>I am interested in understanding this function set up..</p> <p>I have seen seen three examples like this below:</p> <pre><code>(function(parameterOne, parameterTwo) { functionOne = function(...) { ... }, functionTwo: new function() { }, this.functionThree = function(...) { } })() </code></pre> <p>My questions are as follows:</p> <ol> <li><p>When do one use the construct as given for functionOne vs functionTwo vs functionThree? How would I be able to call the functionOne, functionTwo or functionThree explicitly?</p></li> <li><p>I have seen functions like this:</p> <pre><code>(function(parameter) { functionFour = function(..) { }, .... })(document) </code></pre></li> </ol> <p>What does the <strong>document</strong> in this example indicate? I have been confused about this for a long time now.</p> <ol start="3"> <li><p>I have seen jQuery plugins that follow this structure?</p> <pre><code>(function($) { $.fn.myCustomPlugin: function(...) { } })(jQuery) </code></pre></li> </ol> <p>Why is <strong>$</strong> passed to the function and <strong>jQuery</strong> passed at the end? I apologize as this may be rudimentary questions to some of you but these have stymied me for couple of weeks now and I am desperate to get any answers I can.</p> <p>Thanks,</p> <p>Kartik</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.
 

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