const photoGallery = (title, dimensions, date) => {
return {
title,
dimensions,
date,
info() {
console.log(
`Dimenstions of the photo ${this.title} are ${this.dimensions}`
);
},
publishInfo: () => {
console.log(
`Foto was published ${Math.floor(
(new Date().getTime() - date.getTime()) / 1000
)} seconds ago`
);
}
}
}
const photo1 = photoGallery(
"My dog",
"1920x1080",
new Date()
);
photo1.info();
/* Dimenstions of the foto "My dog" are 1920x1080 */
setTimeout(() => photo1.publishInfo(), 2000);
/* Foto "My dog" was published 2 seconds ago */
Not understanding how setTimeout function is working here.
If I call photo1.publishinfo() again in the console I get updated seconds, how?