javascript settimeout evaluate variables now versus later

  javascript, settimeout
function myFunction() {
var now = 3;
var later = 3;
setTimeout(function(){ alert(now * later); }, 1000);
now++;
later++;
}

The above code will alert the value "16", because both variables will be 4 when it executes.
Is there a way to get the value "now" to evaluate right now at its current value so that the final result is 12?

Source: Ask Javascript Questions

LEAVE A COMMENT