Note that there are some explanatory texts on larger screens.

plurals
  1. POQuestions about jQuery patterns
    text
    copied!<p>So i decided to finally learn something about jQuery and as i needed a simple function for one of my projects, i started to search for a good pattern.</p> <p>I began with the official <a href="http://docs.jquery.com/Plugins/Authoring" rel="nofollow">guide</a> but soon found many other possible templates. I will reference two of them to ask my questions:</p> <p><a href="http://www.impressivewebs.com/my-current-javascript-design-pattern/" rel="nofollow">First one</a></p> <p><a href="http://jsfiddle.net/7snNz/" rel="nofollow">Second one</a></p> <p>The first pattern seems to be a lot more cleaner to me, i like the idea of the namespace very much. But, how is this used? Do i write my whole functions as methods of the namespace, then calling all of them in the <code>init()</code> and finally just call this one method <code>init()</code> in the <em>IIFE</em>, or should i call the necessary methods directly in the <em>IIFE</em>?</p> <p>I feel like this question is very idiotic, but i just can't understand the usage.</p> <p>The second pattern i even more complicated to me. Have a look at this:</p> <pre><code>;(function ( $, window, document, undefined ) { //... })( jQuery, window, document ); </code></pre> <p>What are all these parameters, where do i set them and why are they needed? What is the disadvantage of the wrapper in the first sample?</p> <p>The diversity of possibilities is overwhelming, i don't know where to start or how to figure ot the right thing for me.</p>
 

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