Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>jsFiddle's <em>(very surprising)</em> default is to put your code in a <code>window</code> <code>load</code> handler. (You can see this on the left at the top, the second drop-down box says "onload".) That happens <strong>very</strong> late in the loading process, long after <code>ready</code> has fired. So the functions aren't added until after you've tried to run them.</p> <p>If the other developers put their functions in <code>Utils.funcs</code> in <code>script</code> elements after your element defining <code>Utils</code> but without waiting for a <code>load</code> event, it's fine: <a href="http://jsfiddle.net/XvQtF/1/" rel="nofollow">Updated Fiddle</a></p> <hr> <p>For what it's worth, though, I would lean toward using a pub/sub solution rather than a single function. If you want to have more than one <code>start</code> function, for instance, your current structure doesn't allow it.</p> <p>jQuery has <code>Deferred</code> and <code>Promise</code> now, which can be used for this. Here's a simple example of that: <a href="http://jsbin.com/iceruf/1" rel="nofollow">Live Copy</a> | <a href="http://jsbin.com/iceruf/1/edit" rel="nofollow">Live Source</a></p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"&gt;&lt;/script&gt; &lt;meta charset=utf-8 /&gt; &lt;title&gt;Pub/Sub with Deferred and Promise&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;script&gt; (function($) { // Deferred objects for our app states var start = new $.Deferred(), finish = new $.Deferred(); window.Utils = { start: start.promise(), // Only expose the Promise of each finish: finish.promise() // " " " " " " }; $(function() { alert("Calling funcs..."); // Start the app start.resolve(); // Finish the app (or whatever) finish.resolve(); }); })(jQuery); &lt;/script&gt; &lt;script&gt; // Module 1 Utils.start.then(function() { alert("Module 1 Started!"); }); Utils.finish.then(function() { alert("Module 1 Finished!"); }); &lt;/script&gt; &lt;script&gt; // Module 2 Utils.start.then(function() { alert("Module 2 Started!"); }); Utils.finish.then(function() { alert("Module 2 Finished!"); }); &lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    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.
    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