I have a piece of code which has two nested functions inside a main one.
How do I retrieve the nested functions using this keyword? Is it possible?
I have tried times().present() and new times().present() , none of them seem to work and return undefined.
I have found similar examples on w3School but cant seem to implement it in this case.
Thanks in advance.
function times() {
var timingObj = function() {
this.present = currentTime;
this.past = pastTime;
};
var currentTime = function() {
var hourMin = new Date().getHours() + ":" + new Date().getMinutes();
return hourMin;
};
var pastTime = function() {
if (new Date().getDay() == 5) {
return "07:40"
} else {
return "16:30"
}
};
return timingObj;
}
console.log(times().present());
//console.log(new times().present());
classfor this?new (times())().present()newoperator on the function returned bytimes. Not ontimesitself.