Implement Code Modularity: Don’t Cajole an Entire Project

Note

Testing code often by passing it through the cajoling process can help eliminate issues early and give developers a good idea of their project’s progress.

One of the worst things that a developer can do when cajoling a block of code is to attempt to cajole a large amount of JavaScript at once. (If you are new to Caja, doing this might traumatize you.) Most likely what will be produced is an extensive number of warnings and errors about issues with the code, many of which may be reported due to other errors or warnings in the code. This will tend to scare away many developers and may not be a very accurate representation of the code’s issues.

Developing code in a modular fashion—e.g., building encapsulated reusable blocks in standard functions—is the first step in ensuring that it can be tested in blocks. The goal to this approach is the ability to integrate function by function into the script that is being cajoled, so you can deal with errors and warnings from the cajoling process in a much more manageable way.

When migrating an existing code base to an environment that runs Caja, you can use this approach as well. Working with small blocks of code instead of attempting to debug an entire code base can help you manage the output of the cajoling process.

Get Programming Social Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.