What, in your opinion, are the advantages and disadvantages of
dependency-injecting non-instantiable objects in JavaScript?
Some context you may want to explore are:
- Unit-testing
- Is it worth dep-injecting it? After all, you can overwrite the
non-instantiable "static" dependency to a fake object for each test
even without dep-injection.
- Refactoring
- Will it become more difficult to locate & refactor the non-
instantiable dependency?
- Readability
- Which implementation is easier to follow? Is the implicitness or
explicitness important to you?
- File-size
Code
-----
Non-instantiable object:
WindowFactory = {
buildWindow: function() {
return {};
}
};
Dependency-Injected:
(House = function(windowFactory) {
this.windowFactory = windowFactory;
}).prototype = {
build: function() {
var window = this.windowFactory.buildWindow();
}
};
var house = new House(WindowFactory);
vs. The Non-Dependency-Injected variant:
(House = function() {
}).prototype = {
build: function() {
var window = WindowFactory.buildWindow();
}
};
var house = new House();
Note: I've also posted this question on SO (http://stackoverflow.com/
questions/5288368/advantages-disadvantages-of-dependency-injecting-non-
instantiable-objects), but unfortunately it hasn't received any
answers yet.
--
To view archived discussions from the original JSMentors Mailman list:
http://www.mail-archive.com/[email protected]/
To search via a non-Google archive, visit here:
http://www.mail-archive.com/[email protected]/
To unsubscribe from this group, send email to
[email protected]