Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I am also very interested in what other people have to say about this. The approach I've taken is to use object literal notation to store the bulk of the function, and store these in one file included on all pages (the library)</p> <pre><code>uiHelper = { inputDefault:function(defaulttext){ // function to swap default text into input elements }, loadSubSection:function(url){ // loads new page using ajax instead of refreshing page }, makeSortable:function(){ // apply jQuery UI sortable properties to list and remove non javascript controls } } </code></pre> <p>Then I include a .js file on any page that needs to use the library that ties the elements on that page to the function in the library. I've tried to make each function as reuseable as possible and sometimes the event binding function on the page calls several of my library functions.</p> <pre><code>$(document).ready(function(){ $('#mybutton').live('click',uiHelper.loadSubSection); //more complicated helper $('#myotherbutton').live('click',function(){ uiHelper.doThisThing; uiHelper.andThisThing; }); }); </code></pre> <p>edit: using jsDoc <a href="http://jsdoc.sourceforge.net/" rel="nofollow noreferrer">http://jsdoc.sourceforge.net/</a> notation for commenting for these functions can produce documentation for the 'library' and helps keep your code easy to read (functions split by comments).</p> <p>The following question is along similar lines to your own - you should check it out...</p> <p><a href="https://stackoverflow.com/questions/247209/javascript-how-do-you-organize-this-mess">Commonly accepted best practices around code organization in JavaScript</a></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