dependency injection or import modules
I am mainly a PHP programmer, but have been in contact
with 4 JavaScript teams for the past year or so.
As an object-oriented programmer the dependency injection
principle would seem the best way, however I have been told
otherwise by few JS developers. JS is a whole different world.
Because JavaScript allows you to monkey patch anything and
everything using very simple techniques, JavaScript
developers learned to adapt a different technology on
how to build larger scale JavaScript applications.
Most of these are build as sets of self-contained modules,
which expose funcionality through public exports, hiding
internals of the module as not to allow others to rewrite
the functions on which you rely.
The usual approach usually is to even go as far as to not
expose a constructor what so ever but rather expose
constructing of an object using a factory wrapper -
for the exact same reason: if you give someone access
to an object they can instantiate directly they are
allowed to change anything.
By taking advantage of the modular design you deny
others to fiddle with your functions you expect to
work, but you still have the ability to test your
modules - through the public API of the required file, the API you created.