title: JavaScript inner function prints previous value
body: <p>Although code like this is probably not best practice, I ran into something strange while working the other day. Recreating it as a simple example, I expected the following code to alert 'dog' and then 'cat', but instead it alerted 'dog' twice. By my understanding of JavaScript closure, that seems like very odd behavior to me. Anyone have a good explanation for this?</p>
  
  <pre><code>var printMan = {
      printer: function(animal){
          this.innerPrinter =  this.innerPrinter || function(){
               alert(animal)   
          }
          this.innerPrinter(animal)
      }
  }
  
  printMan.printer('dog' )
  printMan.printer('cat') 
  </code></pre>
  
  <p>Here's the <a href="http://jsfiddle.net/8xBvH/" rel="nofollow">Fiddle</a></p>
  
  <p>Edit -----
  Thanks everyone for the great explanations. This is one of the reasons why I love this language - there's a great community here. I thought I knew a great deal about the language, but I was wrong about how this function would work. For anyone reading this, it's probably best to not do something like this example. </p>