Hi Peter, You're right, I didn't give much context did I... Here it is:
My primary goal is to make the code above testable. I've gotten into a habit of externalizing instantiable dependencies (e.g var window = new Window(); var house = new House(window);). This helps when unit- testing instantiable objects (e.g. House), since instead of the real dependencies (Window) I can instantiate the object with a fake (var fakeWindow = {}; var house = new House(fakeWindow);), and not have to worry about redundantly testing the dependencies while testing my object. (This form of dependency-injection is also useful when testing objects that depend on some data being retrieved via XHR, DOM-events, sessionStorage, or cookie.) Now, when the dependency is an instantiable object itself, the benefits are clear to me; but when the dependency is a non- instantiable object (e.g. WindowFactory in the code above), I have second thoughts about the usefulness. That's the reason I've posted the question. - GC On Mar 21, 4:06 am, Peter van der Zee <jsment...@qfox.nl> wrote: > On Mon, Mar 14, 2011 at 1:12 AM, georgecalm <georgec...@gmail.com> wrote: > > What, in your opinion, are the advantages and disadvantages of > > dependency-injecting non-instantiable objects in JavaScript? > > What are you trying to accomplish...? > > One disadvantage is that this is at first glance not obvious :) > > - peter -- To view archived discussions from the original JSMentors Mailman list: http://www.mail-archive.com/jsmentors@jsmentors.com/ To search via a non-Google archive, visit here: http://www.mail-archive.com/jsmentors@googlegroups.com/ To unsubscribe from this group, send email to jsmentors+unsubscr...@googlegroups.com