Extensible Modules for JavaScript
Résumé
The module pattern in JavaScript is commonly used to encapsulate definitions by using closures. However, closures prevent module definitions from being extended at runtime. We propose a simple pattern that not only opens the module, but allows one to extend the module definitions in layers. The pattern leverages the with construct and the prototype delegation mechanism of JavaScript to mimick dynamic binding, while minimizing the changes made to the module code.