JavaScript Pop Quiz
In essay or point form, compare and contrast:
thisCell.onclick = function() { set_datetime( dt_current_day.valueOf(), true); };and thisCell.onclick =
function (day) {
return function() { set_datetime( day, true); };
}(dt_current_day.valueOf());
Do not limit yourself to describing the run-time behaviour as specified in the language specification. Discuss the implications of each choice in the broader context of programming and software design.
Hint 1: Consider the possibility that these statements may be executed more than once, that this_cell may refer to different objects when these statements are executed more than once, and that dt_current_day may have different values when these statements are executed more than once.
Hint 2:
SICP.
Hint 3:
var cTable = document.getElementById("calendarTable");
var dt_current_day = new Date(...),
var iRow = 1;
while (dt_current_day.getMonth() == dt_current.getMonth()
|| dt_current_day.getMonth() == dt_firstday.getMonth()) {
iRow = iRow + 1;
var thisRow = cTable.rows[iRow];
for (var n_current_wday=0; n_current_wday<7; thiscell =" thisRow.cells[n_current_wday];" innerhtml =" dt_current_day.getDate();"> thisCell.onclick =
function (day) { return function() {
set_datetime( day, true); }; }(dt_current_day.valueOf());
...
dt_current_day.setDate(dt_current_day.getDate()+1);
}
}
Hint 4:
JavaScript Pop Quiz Remarks