title: jQuery plugin returning "Cannot read property of undefined"
body: <p>I'm trying to do something i've done numerous times. I can't figure out why this isn't working. No matter how i write the jQuery code, it doesn't work. <code>menuitems[i].action()</code> just does NOT work. Below is <strong>Example 1</strong> in which this example, no matter what item is clicked it returns the last item's action (in this example it's the <code>alert('Forward!')</code>). The 2nd returns undefined property. The full error below.</p>
  
  <p>My jQuery plugin is called like this (examples below are what happen with this same call):</p>
  
  <pre><code>$('p').contextMenu([
      {
          name:'Back',
          action:function(){
              alert('Back!');
          },
          icon:'http://cdn.iconfinder.net/data/icons/crystalproject/16x16/actions/agt_back.png'
      },
      {
          name:'Forward',
          action:function(){
              alert('Forward!');
          },
          icon:'http://cdn.iconfinder.net/data/icons/crystalproject/16x16/actions/agt_forward.png'
      }
  ]);
  </code></pre>
  
  <p><strong>Example 1:</strong></p>
  
  <pre><code>for (i in menuitems){
      $('&lt;li/&gt;',{
          'html':'&lt;img src="'+menuitems[i].icon+'"&gt;'+menuitems[i].name,
          'class':o.itemClass,
          'click':function(){
              menuitems[i].action();
          }
      }).appendTo('.'+o.listClass);
  }
  </code></pre>
  
  <p>This returns an alert with Forward! no matter which item, Back or Forward, is clicked.</p>
  
  <p><strong>Example 2:</strong></p>
  
  <pre><code>var len = menuitems.length;
  for (var i = 0; i &lt; len; i++){
      $('&lt;li/&gt;',{
          'html':'&lt;img src="'+menuitems[i].icon+'"&gt;'+menuitems[i].name,
          'click':function(){
              menuitems[i].action();
          },
          'class':o.itemClass
      }).appendTo('.'+o.listClass);
  }
  </code></pre>
  
  <p>I get:</p>
  
  <blockquote>
    <p>Uncaught TypeError: Cannot read
    property 'action' of undefined</p>
  </blockquote>
  
  <p>Other random things i tried were detaching the click and reattaching it outside of that <code>appendTo()</code> block, changed <code>action()</code> to <code>newtest()</code> to make sure it wasn't conflicting with any built in keywords. I also tried doing a <code>$('body').append('&lt;li&gt;{blah blah}&lt;/li&gt;').find('li').click(function(){/*blah blah*/});</code> but it still returned the same thing. I'm outta ideas!</p>