Closure
by marbx
JavaScript
//amrashid
function hello(planet) {
var greeting = `At ${new Date().toISOString()} say Hello`;
//Functionality here is to greet
return function closureThatFixesTheFunctionalityAtAGivenState_i_e_Time_here() {
console.log(`${greeting} ${planet}`);
}
}
var helloWorld = hello('world');
var helloMars = hello('Mars');
function delay(time) {
return new Promise(resolve => setTimeout(resolve, time));
}
helloWorld();
//Will apply the functionality at a fixed state (time in our case),
//i.e when the function was "closed/stamped". In our case it was at line above --> var helloMars = hello('Mars');
delay(1000).then(()=>helloMars());