This typescript:
enum days { sun = 1, mon = 0, tues };
compiles to this javascript:
var days;
(function (days) {
days[days["sun"] = 1] = "sun";
days[days["mon"] = 0] = "mon";
days[days["tues"] = 1] = "tues";
})(days || (days = {}));
;
This first part: days[days["sun"] = 1] = "sun";
first evaluates days["sun"] = 1 which:
- makes sure that you're able to call
days.sun and get value 1
- returns the value set at key "sun" => 1. This means that initially
days[1] will be set to "sun".
The second part: days[days["mon"] = 0] = "mon";
- makes sure that you're able to call
days.mon and get value 0
- returns the value set at key "mon" => 0. So
days[0] will be set to "mon".
This third part however: days[days["tues"] = 1] = "tues";
evaluates days["tues"] = 1 which
- makes sure that you're able to call
days.tues and get value 1
- also returns the value set at key "tues" => 1
This means that at this point days[1] will be overwritten with value "tues"