I've been reading O'Reilly's JavaScript: The Definitive Guide (6th ed), and have been examining the very first example program -- a loan calculator. 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.
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?
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:
run() {
getdata();
calculate();
if (isFinite(monthly)) {
display();
save(arg1, arg2, arg3, arg4); }
else {
cleardisplay(); }
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.