Witam.
function classCalendar() {
this.value = new Array();
this.month = new Array();
this.value = function(value)
{
var value = value.split('-');
value[1] = value[1] - 1;
this.value = value;
this.month = value;
}
this.prev = function()
{
var date = new Date(this.month[0], this.month[1], '01');
date.setMonth(this.month[1] - 1);
this.month[1] = date.getMonth();
this.month[0] = date.getFullYear();
console.log(this.value);
}
this.next = function()
{
var date = new Date(this.month[0], this.month[1], '01');
date.setMonth(this.month[1] + 1);
this.month[1] = date.getMonth();
this.month[0] = date.getFullYear();
console.log(this.value);
}
}
var calendar = new classCalendar();
calendar.value('2014-11-12');
calendar.next();
calendar.next();
calendar.next();
Powyżej jest kod, który nie działa tak jakbym chciał. Jeśli wywołamy funkcję calendar.next() to zmienia się zmienna this.value, a jest zadeklarowana tylko w momencie tworzenia obiektu calendar.value('2014-11-12'). Nie wiem dlaczego ta zmienna zmienia wartość.
Ps. nie wiem do końca, czy tu chodzi o zmienne, czy też o coś innego dlatego temat wątku nie do końca może być trafny...
Z góry dziękuję za pomoc.