TypeScript小知識(shí):遍歷enum (暫時(shí)記錄)
enum BlockPrefab{
BLOCK2 = 0,
BLOCK4,
BLOCK8,
BLOCK16,
BLOCK32,
BLOCK64,
BLOCK128,
BLOCK256,
BLOCK512,
BLOCK1024,
BLOCK2048
}
let num = BlockPrefab.BLOCK128;
let smth = BlockPrefab[num];
let xx = BlockPrefab[smth];

ts 的enum編譯為js如圖所示
BlockPrefab["BLOCK2"] = 0 可以相互轉(zhuǎn)化 以此來(lái)實(shí)現(xiàn)enum

浙公網(wǎng)安備 33010602011771號(hào)