title: Calling a jQuery plugin's private function in setInterval()
body: <p>I'm working on a jQuery plugin. Basically, what I need it to do is to call a private function in my plugin with setInterval. It looks like there's a lot of different ways to create a jQuery plugin. I'm using the following method because I find it clear but if there's a working solution that requires me to change the way I structure my plugin, I'm opened...</p>
  
  <p>I simplified my plugin to keep only the problematic part:</p>
  
  <pre><code>(function($){
      $.fn.something = function(options)
      {
          var opts = $.extend({}, $.fn.something.defaults, options);
          return this.each(function()
          {
              var $this = $(this);
              $this.click(function(){
                  startSomething($this);
              });
          });
          // Private function
          function startSomething($this)
          {
              // $this is defined
              setInterval(doSomething, 1000);
          };
          // Another private function
          function doSomething($this)
          {
              // $this is undefined
          };
      };
      $.fn.something.defaults = {
          my_option: 'value'
      };
  })(jQuery);
  </code></pre>
  
  <p>The problem is that I want to call doSomething() every second. But I need to keep the reference to my element (in the $this variable). If I use setInterval(doSomething), the function is called all right, but I don't have the $this variable as a parameter. If I use setInterval("doSomething($this)") the function is undefined because it's trying to find it in the global context.</p>
  
  <p>So what would be the solution here to call my private function and be able to pass an argument to it?</p>
  
  <p>Thanks</p>