When I click the anchor, I find that date is not defined. How should I make sure the parameters are in the scope of the self-calling function that I pass to onclick?
var date = today; // today is well-defined at this point.
html += '<a onclick="(function(obj, myDate) { \
return function() { \
obj.render(myDate.setMonth(myDate.getMonth() - 1)); \
}; \
})(this, date);"><</a>'
Edit: Is this HTML valid?
today is well-defined. This snippet of code lives inside this function:
Calendar.prototype.render = function(date) {
}
When an event is raised, the only context it has is the window context.
you have to set up a global var in order for it to be available within the event callback code when using
on<event>attributes.