Loose augmentation of modules

When we try to enhance a module using the augmentation technique previously discussed, we pass a reference of the module to another part of our code which is responsible for doing the augmentation work.

How can we add functionality to an object that has not been loaded or created yet?

The answer to this question becomes very important when our modules (files) are loaded in an asynchronous fashion, and we have no way of making sure that our original module is loaded before the augmentation code that enhances the module.

One of the beautiful and powerful aspects of JavaScript is its ability to add properties to objects dynamically, at any time during code execution. This allows us to add functionality or modify our original ...

Get Modular Programming with JavaScript 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.