title: What underlies this JavaScript idiom: var self = this?
body: <p>I saw the following in the source for <a href="http://webkit.org/misc/DatabaseExample.html" rel="noreferrer">WebKit HTML 5 SQL Storage Notes Demo</a>:    </p>
  
  <pre><code>function Note() {
    var self = this;
  
    var note = document.createElement('div');
    note.className = 'note';
    note.addEventListener('mousedown', function(e) { return self.onMouseDown(e) }, false);
    note.addEventListener('click', function() { return self.onNoteClick() }, false);
    this.note = note;
    // ...
  }
  </code></pre>
  
  <p>The author uses <em>self</em> in some places (the function body) and <em>this</em> in other places (the bodies of functions defined in the argument list of methods).  What's going on?  Now that I've noticed it once, will I start seeing it everywhere?</p>