Note that there are some explanatory texts on larger screens.

plurals
  1. POjavascript strategy / best practice
    primarykey
    data
    text
    <p>I'm getting into writing some more complex javascript applications, and I'm running into the limitations of my own knowledge-- please forgive any naming errors or obvious noob stuff, I'm not a js pro!</p> <p>I have about 4 or 5 scripts I've put in their own files, just to keep things a little easier to maintain. So maybe there's one script that deals with building page elements (like complex forms), another that just handles data, creating generic ajax request objects, defining parsers and error functions for the data returned, and another that is purely display-oriented.</p> <p>I've set global variables in the page that then get populated by various scripts that get loaded at run time. For example, I define <code>var myapp = { };</code> in the main HTML page, and then in the scripts various function populate this "namespace" like:</p> <pre><code>myapp.myfunction = function(){ // do stuff } </code></pre> <p>The problem is that despite all the scripts including a <code>$(document).ready(function()</code> block that wraps all function definitions, when a function is called from one script that refers to another (that is, if my <code>data.js</code> file calls a function <code>myapp.myDisplayFunction</code> that is in the <code>display.js</code> file, I sometimes get an <code>Object has no method 'myDisplayFunction'</code> </p> <p>Other than slamming all functions into one massive script, how do you deal with this problem? Is there a best practice that I'm missing? or is this just a question of specifying a different order that the scripts are called in?</p> <p>Thanks </p>
    singulars
    1. This table or related slice is empty.
    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.
 

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