Undefined parameter in a javascript event
<p>When I click the anchor, I find that <code>date</code> is not defined. How should I make sure the parameters are in the scope of the self-calling function that I pass to <code>onclick</code>?</p>

<pre><code>var date = today; // today is well-defined at this point.

html += '&lt;a onclick="(function(obj, myDate) { \
        return function() { \
           obj.render(myDate.setMonth(myDate.getMonth() - 1));  \
        };  \
      })(this, date);"&gt;&amp;lt;&lt;/a&gt;'
</code></pre>

<p>Edit: Is this HTML valid?</p>

<p><code>today</code> is well-defined. This snippet of code lives inside this function:</p>

<pre><code>Calendar.prototype.render = function(date) {

}
</code></pre>
