What's the best way to define a variable within the scope of a javascript function?
<p>I would like to define variables within scope of <code>paginate()</code>. However, any variable defined with <code>this</code> (e.g. <code>this.parentlist</code>) is not available within the jQuery <code>click</code> method</p>

<pre><code>var paginate = function(elt) {
          //would like to define variables within scope of paginate()
          //however, any variable defined with this (e.g. this.parentlist) is not available within the jQuery click method
          this.parentlist = elt.find('ul');
          var listitems = elt.find('li');
          this.listcount = this.list.find('li').size();
          var showitems = '3';

          this.numberofpages = ~~((this.count / this.show) + 1);

          this.parentlist.after('&lt;ul class="links"&gt;&lt;/ul&gt;');

          for(i=1;i&lt;=this.numberofpages;i++) {
            $('.links').append('&lt;li&gt;&lt;a href="#'+i+'"&gt;'+i+'&lt;/a&gt;&lt;/li&gt;')
          };

          //click a link
          $('.links a').click(function() {
            //this.parentlist is not available here
            listitems.hide();
            this.start = listitems.index() * showitems;
            this.end = (this.start + 1) * showitems;
            this.selected = listitems.slice(this.start,this.end).show().addClass('selected');
            console.log(this.selected);
            console.log(this.parentlist);
          }); 
  };

  paginate($('.pages'));
</code></pre>
