A module can be characterized by its source code, the top enclosing
environment and the environment the module has been defined in.
extend will keep the latter two intact and only change the source
code. That means that the new module will have the same scope as the module
to be extended. import, use, and export declarations
can be added as needed.
This approach gives access to all implementation details of a module and
breaks encapsulation. Possible use cases are: unit tests, and hacking the
module system when necessary. For general reuse of modules, consider using
expose and use which are safer to use.
Since extend
will alter the source code, the state of the
module is ignored and will not be present in the new module. A fresh
instance of that new module is returned and can in turn be extended and/or
treated like any other module.