I have an "enumeration" declared like this:
var PlaceType = { PASSABLE_TERRAIN: 1, IMPASSABLE_TERRAIN: 0, SOMEWHAT_PASSABLE_TERRAIN: 2, PATH: 3 };
and a function declared as follows:
setPlaceType(placeType) { this.clear = false; this.placeType = placeType; alert("before switch "+(PlaceType.SOMEWHAT_PASSABLE_TERRAIN==this.placeType)); switch(this.placeType) { case PlaceType.PASSABLE_TERRAIN: { alert("Case PASSABLE"); break; } case PlaceType.IMPASSABLE_TERRAIN: { alert("Case IMPASSABLE"); break; } case PlaceType.SOMEWHAT_PASSABLE_TERRAIN: { alert("Case SOMEWHAT_PASSABLE"); break; } case PlaceType.PATH: { alert("Case PATH"); break; } default: { alert("case default"); } } }
if I call it like this:
setPlaceType(1);
I get the following warnings: "before switch true", "case default"
if I call it like this:
setPlaceType(2);
I get the following warnings: "before switch false", "case default"
In other words, the function is called with the correct argument, which when executed (it seems to me) is the same comparison as the switch, but through "==" I get the correct behavior, but the switch never matches the values ββin the corresponding case. Does anyone know why?
source share