So I started working with TypeScript recently and I'm enjoying it so far, but there is a problem that I simply can't understand why it's not working properly.
the "var" keyword is still accessible in TypeScript naturally and I know that it's a function scope, versus block scope for the "let" keyword. I have the following code and I can't figure out why it's not working:
class Calendar {
month: number;
months: string[];
weekday: number;
day: number;
constructor() {
this.month = date.getMonth();
this.months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'November', 'December'];
this.weekday = date.getDay();
this.day = date.getDate();
}
nextMonth() {
var months = this.months;
var currentmonth: number = this.month;
el('.icono-caretRight').addEventListener('click', () => {
currentmonth = (currentmonth + 1) % months.length;
}, false);
month = currentmonth;
return month;
}
previousMonth() {
el('.icono-caretLeft').addEventListener('click', () => {
month--;
}, false);
}
}
let calendar = new Calendar();
let month = calendar.month;
let nextmonth = calendar.nextMonth();
console.log(nextmonth);
Look at the nextMonth() function. I don't know why the "month" variable is not being incremented. What exactly am I doing wrong here?
Note: I'm using JSPM + TypeScript (the plugin-typescript).
Thanks in advance!