I am trying to become more familiar with Javascript OOP and so I wrote a little test script but I keep getting an exception when I test it:
Exception:
Uncaught TypeError: Cannot call method 'day' of undefined
Code:
(function () {
function Time (date) {
var self = this;
var timeInWeek = 604800000;
var timeInDay = 86400000;
var dateInMilliSeconds = date.getTime();
self.add = function (num) {
self.day = function () {
var newDate = new Date();
newDate.setTime(dateInMilliSeconds + (timeInDay * num));
return newDate;
};
};
};
var date = new Date();
var time = new Time(date).add(1).day();
console.log(time);
})();
And when I run the test script outside of the IIFE pattern I am getting the exception Time is undefined, I am new to Javascript OOP so when I tried reading other Javascript libraries a good chunk was over my head. Any help is appreciated.