I am trying to accomplish something like this.
/* Code start */
function getCurrentTime()
{
var date = new Date(),
time = date.getTime();
return time;
}
var jsObject = {
"imageOne":"SomeText"+getCurrentTime(),
"imageTwo":"someOtherText"+getCurrentTime()
}
setInterval(function(){
console.log(jsObject.imageOne);
}, 3000);
/* Code end */
Each time the timer is executed I need to execute getCurrentTime() and get the latest time. How do I do it?
If you need to execute things and get a different result each time, you basically need a function:
and:
If really necessary, you can omit the
()with a getter, but using a function is more straight-forward.Using a getter:
This way accessing
obj.imageOnewill evaluate to a different value each time, depending on the current time.