i am newbie to Typescript and i am confused from the generated Javascript below.
Original Typescript:
enum DaysOfTheWeek {
SUN, MON, TUE, WED, THU, FRI, SAT
};
let day: DaysOfTheWeek;
day=DaysOfTheWeek.MON;
if (day === DaysOfTheWeek.MON) {
console.log("Got to go to work!");
}
Generated Javascript:
var DaysOfTheWeek;
(function(DaysOfTheWeek) {
DaysOfTheWeek[DaysOfTheWeek["SUN"] = 0] = "SUN";
DaysOfTheWeek[DaysOfTheWeek["MON"] = 1] = "MON";
DaysOfTheWeek[DaysOfTheWeek["TUE"] = 2] = "TUE";
DaysOfTheWeek[DaysOfTheWeek["WED"] = 3] = "WED";
DaysOfTheWeek[DaysOfTheWeek["THU"] = 4] = "THU";
DaysOfTheWeek[DaysOfTheWeek["FRI"] = 5] = "FRI";
DaysOfTheWeek[DaysOfTheWeek["SAT"] = 6] = "SAT";
})(DaysOfTheWeek || (DaysOfTheWeek = {}));
;
var day;
day = DaysOfTheWeek.MON;
if (day === DaysOfTheWeek.MON) {
console.log("Got to go to work!");
}
Questions:
The var DaysOfTheWeek does not seems like it's an array. From what i understand an array needs an empty array instance like below:
var ar = [];
Arrays only uses index. Yet we have DaysOfTheWeek[DaysOfTheWeek["SUN"] = 0] = "SUN"; Seems like associative arrays? Can someone slowly explain in steps?
DaysOfTheWeek[DaysOfTheWeek["SUN"] = 0] = "SUN"; -- breaking it down below
1. DaysOfTheWeek["SUN"] = 0 -- seems like assigning key "SUN" with value 0?
2. DaysOfTheWeek[DaysOfTheWeek["SUN"] = 0] = "SUN" -- this part confuses me!!
On function (DaysOfTheWeek) itself, i am confused stmt B construct at the bottom of this function. What is this?
Appreciate any help.