Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There is a lot to say on the subject.</p> <p>First, you seem to wonder about the difficulty of keeping your code understandable and maintainable. There isn't a magic recipe. I work on fairly large JavaScript projects and face this issue every day.</p> <p>Because JavaScript is not statically checked, the amount of knowledge one needs to maintain about the code is greater than with some other languages. Because in JavaScript, you can never be sure of what an object does or what data it contains until the code actually gets executed, it can be very tedious to write complex logic and workflows.</p> <p>Our answer to that is to make our code as simple as possible. Complex logic is encapsulated into simple, reusable objects. Each function has clear responsabilities, and little side effects. Our code is mostly context-agnostic (it can be re-used in other projects, each module has very few or no dependencies). We try to avoid functions that require a lot of arguments, or objects that do a lot of things. We also avoid writing code that requires a lot of conditional statements. That gives us a library of functionalities that allows us to compose complex logic with little effort. In the end, all that's needed in the HTML view are a few one-line calls to functions. Everything else is in .js files.</p> <p>Also, consistency is important. Stick to common patterns. Make your code predictable.</p> <p>Our typical JavaScript file only contains one object. Files are grouped by area of concern (controls, core, services, etc.).</p> <p>Using libraries such as jQuery is a good idea because they care of most of the boiler-plate code and are supported by large communities of developers. They can simplify aspects of the development (e.g. dealing with the DOM, Ajax, JSON serialization).</p> <p>Unit-testing has been useful in some cases. We use <a href="http://docs.jquery.com/QUnit" rel="nofollow">QUnit</a> to test our JavaScript code. It helps us detect unexpected behaviors or breaking changes.</p> <p>Depending on your needs, you might also try languages or frameworks that compile code into JavaScript. There are <a href="https://github.com/jashkenas/coffee-script/wiki/List-of-languages-that-compile-to-JS" rel="nofollow">pages with comprehensive lists of those</a>. There are pros (static checking, better type system) and cons (poor support for libraries, projects that get dropped).</p> <p>Regarding using Ajax to communicate with the server, I recommend that you look into <a href="http://en.wikipedia.org/wiki/Representational_State_Transfer" rel="nofollow">RESTful principles</a>. Ajax is just a tool. You can do a lot if things with it.</p>
    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. 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