I'm re-evaluating my thoughts on constructor based dependencies vs setter dependencies in JavaScript. I'm trying to see if the same reasons we avoid setter injection in static language like C# and Java still apply in JavaScript.
In other words, why is this:
var a = new A();
var b = new B();
var c = new C(a, b);better than this:
var a = new A();
var b = new B();
var c = new C();
c.a = a;
c.b = b;What are the reasons that you would choose constructor parameters vs setters, and why?
What other options are there for runtime composition of the c object, so that it can correctly make use of a and b? When would you choose those options?
I think we're presenting this question with a slight bias. I'd really love to have people examine the code in question and make concrete arguments about what they don't like and why.
The context of this discussion is here:
http://hilojs.codeplex.com/discussions/391074
I wrote this JavaScript code with this test. I was responding to this earlier code. However, Derick and I both agree that the earlier code is not desirable.
Perhaps a better example to compare would be this code and this test.