<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Dependency-Injection and JavaScript closures</title>
	<atom:link href="http://misko.hevery.com/2010/05/29/dependency-injection-and-javascript-closures/feed/" rel="self" type="application/rss+xml" />
	<link>http://misko.hevery.com/2010/05/29/dependency-injection-and-javascript-closures/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=dependency-injection-and-javascript-closures</link>
	<description>Testability Explorer</description>
	<lastBuildDate>Thu, 19 Jan 2012 16:42:57 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Some useful readings &#124; Joshy&#039;s microblog</title>
		<link>http://misko.hevery.com/2010/05/29/dependency-injection-and-javascript-closures/comment-page-1/#comment-17513</link>
		<dc:creator>Some useful readings &#124; Joshy&#039;s microblog</dc:creator>
		<pubDate>Thu, 19 Jan 2012 16:42:57 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?p=623#comment-17513</guid>
		<description>[...] http://misko.hevery.com/2010/05/29/dependency-injection-and-javascript-closures/ [...]</description>
		<content:encoded><![CDATA[<p>[...] <a href="http://misko.hevery.com/2010/05/29/dependency-injection-and-javascript-closures/" rel="nofollow">http://misko.hevery.com/2010/05/29/dependency-injection-and-javascript-closures/</a> [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: misko</title>
		<link>http://misko.hevery.com/2010/05/29/dependency-injection-and-javascript-closures/comment-page-1/#comment-6251</link>
		<dc:creator>misko</dc:creator>
		<pubDate>Thu, 03 Feb 2011 21:03:18 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?p=623#comment-6251</guid>
		<description>@Scott,

yes, that is right on.</description>
		<content:encoded><![CDATA[<p>@Scott,</p>
<p>yes, that is right on.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Scott</title>
		<link>http://misko.hevery.com/2010/05/29/dependency-injection-and-javascript-closures/comment-page-1/#comment-6244</link>
		<dc:creator>Scott</dc:creator>
		<pubDate>Thu, 03 Feb 2011 16:08:28 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?p=623#comment-6244</guid>
		<description>Thanks, Misko!  I think that I understand what you are saying.  Would it then be accurate to state the  following?:

An injectable can ask for a newable (or a primitive type) in its constructor when the newable is used for configuration of the injectable and when the injectable treats the newable as a constant.  So injecting, for example, an URL or a timeout value in an injectable might be an acceptable use when these are used by the injectable as constants for its configuration.

Is that understanding correct or did I mangle the message?  Thanks!</description>
		<content:encoded><![CDATA[<p>Thanks, Misko!  I think that I understand what you are saying.  Would it then be accurate to state the  following?:</p>
<p>An injectable can ask for a newable (or a primitive type) in its constructor when the newable is used for configuration of the injectable and when the injectable treats the newable as a constant.  So injecting, for example, an URL or a timeout value in an injectable might be an acceptable use when these are used by the injectable as constants for its configuration.</p>
<p>Is that understanding correct or did I mangle the message?  Thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: misko</title>
		<link>http://misko.hevery.com/2010/05/29/dependency-injection-and-javascript-closures/comment-page-1/#comment-6178</link>
		<dc:creator>misko</dc:creator>
		<pubDate>Mon, 31 Jan 2011 19:11:36 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?p=623#comment-6178</guid>
		<description>@Scott,

very good observation! The issue with newables and injecting them in, is that the injector does not know how to make a String. Not any string will do, only a specific one in this case. So the rule holds, but in this case the String acts as a configurable constant. You would not instantiate the constant in your code, like you may instantiate an array or a hash, instead you expect someone to give you the configuration constant. Hence it should be injected.</description>
		<content:encoded><![CDATA[<p>@Scott,</p>
<p>very good observation! The issue with newables and injecting them in, is that the injector does not know how to make a String. Not any string will do, only a specific one in this case. So the rule holds, but in this case the String acts as a configurable constant. You would not instantiate the constant in your code, like you may instantiate an array or a hash, instead you expect someone to give you the configuration constant. Hence it should be injected.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Scott</title>
		<link>http://misko.hevery.com/2010/05/29/dependency-injection-and-javascript-closures/comment-page-1/#comment-6125</link>
		<dc:creator>Scott</dc:creator>
		<pubDate>Sat, 29 Jan 2011 14:42:07 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?p=623#comment-6125</guid>
		<description>Misko,

I&#039;m confused by this example and how to reconcile this with previous advice you&#039;ve given about newables and injectables.

Is the Java Greeter class intended as an injectable or newable?  It seems intended as an injectable since the article revolves around the &#039;greet&#039; verb.  But you&#039;ve said previously (http://misko.hevery.com/2008/09/30/to-new-or-not-to-new/)  that &quot;Injectable can never ask for a non-Injectable (Newable) in its constructor&quot;.  Clearly though here &#039;greeting&#039; is a newable since it is a String.

But if Java Greeter is not intended as an injectable and is instead intended as a newable, then the whole example kind of falls apart since the example is about injectables but newables can&#039;t be injected into injectables, so I assume that Greeter is probably not intended as a newable.

In any case, I&#039;m been trying to resolve this in my head unsuccessfully.  Have you changed your mind about injecting newables into injectables or (more likely) am I misunderstanding something?</description>
		<content:encoded><![CDATA[<p>Misko,</p>
<p>I&#8217;m confused by this example and how to reconcile this with previous advice you&#8217;ve given about newables and injectables.</p>
<p>Is the Java Greeter class intended as an injectable or newable?  It seems intended as an injectable since the article revolves around the &#8216;greet&#8217; verb.  But you&#8217;ve said previously (<a href="http://misko.hevery.com/2008/09/30/to-new-or-not-to-new/" rel="nofollow">http://misko.hevery.com/2008/09/30/to-new-or-not-to-new/</a>)  that &#8220;Injectable can never ask for a non-Injectable (Newable) in its constructor&#8221;.  Clearly though here &#8216;greeting&#8217; is a newable since it is a String.</p>
<p>But if Java Greeter is not intended as an injectable and is instead intended as a newable, then the whole example kind of falls apart since the example is about injectables but newables can&#8217;t be injected into injectables, so I assume that Greeter is probably not intended as a newable.</p>
<p>In any case, I&#8217;m been trying to resolve this in my head unsuccessfully.  Have you changed your mind about injecting newables into injectables or (more likely) am I misunderstanding something?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: misko</title>
		<link>http://misko.hevery.com/2010/05/29/dependency-injection-and-javascript-closures/comment-page-1/#comment-4614</link>
		<dc:creator>misko</dc:creator>
		<pubDate>Fri, 29 Oct 2010 03:24:37 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?p=623#comment-4614</guid>
		<description>@Sjur,

Nouns and verbs need to be in balance. So perhaps a class (noun) is needed in your case to join the two.</description>
		<content:encoded><![CDATA[<p>@Sjur,</p>
<p>Nouns and verbs need to be in balance. So perhaps a class (noun) is needed in your case to join the two.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sjur Kvammen</title>
		<link>http://misko.hevery.com/2010/05/29/dependency-injection-and-javascript-closures/comment-page-1/#comment-4606</link>
		<dc:creator>Sjur Kvammen</dc:creator>
		<pubDate>Thu, 28 Oct 2010 19:36:13 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?p=623#comment-4606</guid>
		<description>Thank you for a very interesting post.
What if the example had two verbs, acting on the same structure (f.ex in java service.start/service.stop). Would you still go for verbs like stopService/startService? Or would you introduce the service-noun to connect the two? (and what if there were 3, 4, 5 verbs etc. ? When would you use nouns/objects?)</description>
		<content:encoded><![CDATA[<p>Thank you for a very interesting post.<br />
What if the example had two verbs, acting on the same structure (f.ex in java service.start/service.stop). Would you still go for verbs like stopService/startService? Or would you introduce the service-noun to connect the two? (and what if there were 3, 4, 5 verbs etc. ? When would you use nouns/objects?)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Zbigniew Lukasiak</title>
		<link>http://misko.hevery.com/2010/05/29/dependency-injection-and-javascript-closures/comment-page-1/#comment-4168</link>
		<dc:creator>Zbigniew Lukasiak</dc:creator>
		<pubDate>Sat, 25 Sep 2010 15:23:22 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?p=623#comment-4168</guid>
		<description>How do you answer to critique like: http://discuss.joelonsoftware.com/default.asp?joel.3.219431 ?  I understand that the motivation you present here is different than the one attacked by Joel - but still it is undeniable that very high level functions are just difficult to think about.</description>
		<content:encoded><![CDATA[<p>How do you answer to critique like: <a href="http://discuss.joelonsoftware.com/default.asp?joel.3.219431" rel="nofollow">http://discuss.joelonsoftware.com/default.asp?joel.3.219431</a> ?  I understand that the motivation you present here is different than the one attacked by Joel &#8211; but still it is undeniable that very high level functions are just difficult to think about.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: misko</title>
		<link>http://misko.hevery.com/2010/05/29/dependency-injection-and-javascript-closures/comment-page-1/#comment-3656</link>
		<dc:creator>misko</dc:creator>
		<pubDate>Fri, 25 Jun 2010 03:52:14 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?p=623#comment-3656</guid>
		<description>@ Johan,

I think I got caught red handed. You bring up a good point which I did not think about. You are correct that in this example the factory is a single method without a class which is a static method. But closures kind of undo the staticness of it.  In java a static method is static and it has all of the issues I mentioned before, but in JavaScript the method has closure (variables declared outside of the method). This makes the method act as a class to which you pass the dependencies through the constructor (closure) and the class has single method which performs the action (equivalent to just calling the method).

So in JavaScript a method without a class has injection (closure) but it also has polymorphism, since the method is passed into the consumer, and you can always inject a different method for testing. So closure and methods as first class citizens undo the static method problem of Java.</description>
		<content:encoded><![CDATA[<p>@ Johan,</p>
<p>I think I got caught red handed. You bring up a good point which I did not think about. You are correct that in this example the factory is a single method without a class which is a static method. But closures kind of undo the staticness of it.  In java a static method is static and it has all of the issues I mentioned before, but in JavaScript the method has closure (variables declared outside of the method). This makes the method act as a class to which you pass the dependencies through the constructor (closure) and the class has single method which performs the action (equivalent to just calling the method).</p>
<p>So in JavaScript a method without a class has injection (closure) but it also has polymorphism, since the method is passed into the consumer, and you can always inject a different method for testing. So closure and methods as first class citizens undo the static method problem of Java.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Johan</title>
		<link>http://misko.hevery.com/2010/05/29/dependency-injection-and-javascript-closures/comment-page-1/#comment-3654</link>
		<dc:creator>Johan</dc:creator>
		<pubDate>Fri, 25 Jun 2010 00:10:24 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?p=623#comment-3654</guid>
		<description>You&#039;ve previously said that you think static functions are not OK and death to testability. But isn&#039;t the createFactories function equivalent to a static function? Did you change your mind and accept that static functions are OK as long as you inject dependencies (in this case a pointer to another static-like function)? 

Otherwise I&#039;m a bit puzzled. You said before that the important part is that your tests must be able to prevent the execution of normal code path (or else you would end up with scenario tests instead of unit tests).</description>
		<content:encoded><![CDATA[<p>You&#8217;ve previously said that you think static functions are not OK and death to testability. But isn&#8217;t the createFactories function equivalent to a static function? Did you change your mind and accept that static functions are OK as long as you inject dependencies (in this case a pointer to another static-like function)? </p>
<p>Otherwise I&#8217;m a bit puzzled. You said before that the important part is that your tests must be able to prevent the execution of normal code path (or else you would end up with scenario tests instead of unit tests).</p>
]]></content:encoded>
	</item>
</channel>
</rss>

