title: JavaScript - Variable undefined within promise chain
body: <p>In the following event listener, event variable is undefined in the <strong><em>then</em></strong> call.   But if the event variable is reassigned to variable with different name it works. What is the difference ?</p>
  
  <pre><code>document.addEventListener(EVENT_REVIEWED, function() {
  
    var someCondition = self.id == model.id;    
    var event = event;  // This does not work. 
    var _event = event; // This works 
  
    Promise.resolve().then(function() {
      return self.checkToLoad();
    }).then(function(){     
      self.postCall = null;
  
      if (someCondition ) {     
        //  Gives an error that Uncaught TypeError: Cannot read property 'detail' of undefined
        self.postCall = {functionName: self.openWindow, params: {mode: "edit", id: event.detail.id}};
      }       
    });
  
  });
  </code></pre>