Solving the Javascript include problem
One problem facing Javascript developers is this: Your class model is spread across multiple Javascript source files. Class A depends on B, C and D. You are now faced with the problem of including the correct Javascript source files in all applications which use class A.
In ordinary HTML/XUL, you have a series of <script src> tags in all applications using class A. When class A starts requiring class E, you have to edit all HTML/XUL files again and manually include class E. And of course, it is very likely that you will miss one place or two which causes parts of the application to break. This is a problem which should be solved at the language level, but is not addressed at all so far in ECMAScript.
One quite elegant solution in the XUL world is using overlays.
Overlays are XML fragments which can be included from multiple source files. Their original purpose is extending XUL pages by merging XUL fragments into existing elements. For example, if you have a XUL page containing:<groupbox id="foo">
<caption label="foo"/>
</groupbox>
<groupbox id="foo">
<textbox id="bar"/>
</groupbox>
<groupbox id="foo">
<caption label="foo"/>
<textbox id="bar"/>
</groupbox>
Here is a real-life example:
<?xml version="1.0" encoding="ISO-8859-1"?>
<overlay xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<box id="classdm">
<script src="../../ge/common/ge_errors.js"/>
<script src="../common/js/dm_akte.js"/>
<script src="../common/js/dm_address.js"/>
<script src="../common/js/dm_damage.js"/>
<script src="../common/js/dm_ubtl.js"/>
<script src="../common/js/dm_vehicle.js"/>
<script src="../common/js/dm_ra_agreement.js"/>
<script src="../common/js/dm_lv_info.js"/>
<script src="../common/js/dm_breakdowns.js"/>
<script src="../common/js/dm_address.js"/>
<script src="../../pa/common/pa_address.js"/>
<script src="../../lv/common/lv_insurances.js" />
<script src="../../lv/common/lv_rvcs.js"/>
</box>
</overlay>
<?xul-overlay href="../common/dm_overlays.xul"?>
...
<page xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<box id="classdm"/>
</page>
