How to idiomatically structure JavaScript
<p>I've been reading O'Reilly's JavaScript: The Definitive Guide (6th ed), and have been examining the very first <a href="http://examples.oreilly.com/9780596805531/examples/01.01.loancalc.html" rel="nofollow">example program -- a loan calculator</a>. However, the structure of this just bugs me -- I know that it's a book example, and hence probably not the best way of going about things for the sake of simplicity, so I'm curious as to how a professional using best practices would structure the same thing.</p>

<p>For example, the main function, calculate(), which is called onChange to any of the input fields, contains within it a TON of stuff that doesn't have anything to do with calculating anything -- display code, for instance -- how would you pull that out to separate concerns?</p>

<p>It'd make me feel better if you could modularize the individual tasks that are to be done and put the major control into the function something like this:</p>

<pre><code>run() {
    getdata();
    calculate();
    if (isFinite(monthly)) {
        display();
        save(arg1, arg2, arg3, arg4); }
    else {
        cleardisplay(); }
</code></pre>

<p>But I have no idea what I'm talking about. Is there some way to do it with the Object Literal pattern? I guess I'm just asking how you would do it idiomatically.</p>
