title: Does a nested anonymous function in Javascript associated with an event handler not work?
body: <p>If I use a <strong>named function</strong> instead,it does do well :</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
     window.onload = function(){
         var img = document.getElementById('im');
          img.onload = fun();
  
     } 
  function fun()
  {
    alert("Image loaded");
  }          
  &lt;/script&gt;
  
  &lt;img src="picture.png" id="im"/&gt;
  </code></pre>
  
  <p>But, my question is that when I try to do the same by using <strong>an anonymous function</strong>(<em>as shown below</em>),why does it not work?</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;   
         window.onload = function(){
         var img = document.getElementById('im');
            img.onload = function(){
  
            alert("Image loaded");
          }
         }            
  &lt;/script&gt;
  
  &lt;img src="picture.png" id="im"/&gt;
  </code></pre>