Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>These four options all create exactly the same result with declining flexibility:</p> <h2>Example #1</h2> <pre><code>$(document).ready(function (){ initialize(); }); function initialize(){ hello(); } </code></pre> <h2>Example #2</h2> <pre><code>$(document).ready(initialize); function initialize(){ hello(); } </code></pre> <h2>Example #3</h2> <pre><code>$(document).ready(function (){ hello(); }); </code></pre> <h2>Example #4</h2> <pre><code>$(document).ready(hello); </code></pre> <p>In the first example, you are creating an anonymous function that will be called at document.ready time. That anonymous function calls a separate function <code>initialize()</code>. Because <code>initialize()</code> is a separate function, it could also be called by other code.</p> <p>In the second example, you just avoid the anonymous function and pass a reference to the <code>initialize</code> function directly. This works slightly faster than the first example (one less function call), but is less flexible if you wanted to call more than one function besides <code>initialize()</code> from the <code>document.ready()</code> handler.</p> <p>In the third example, you just remove the outer <code>initialize()</code> function and just call the one thing inside it that it was doing from an anonymous function.</p> <p>In the fourth example, the anonymous function is again removed and you just pass a direct reference to the <code>hello</code> function so it will be called directly without any intervening functions.</p> <p>The first option gives you the most flexibility because you can call multiple things inside of <code>initialize()</code> and you can also call <code>initialize()</code> from other places in your program. If you don't need those flexibilities, you can pick any one of the other four options as they all produce the same results, each with a little less flexibility.</p>
    singulars
    1. This table or related slice is empty.
    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. 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.
    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