Why Deferred is not working when resolve is inside a function
<p>This code works <a href="http://jsfiddle.net/neerajdotname/k2Q9b/" rel="nofollow">http://jsfiddle.net/neerajdotname/k2Q9b/</a></p>

<p>But this code does not work <a href="http://jsfiddle.net/neerajdotname/k2Q9b/1/" rel="nofollow">http://jsfiddle.net/neerajdotname/k2Q9b/1/</a></p>

<p>Why? </p>

<p>And what's the fix?</p>
