TypeScript小知识:遍历enum (暂时记录)

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 可以相互转化 以此来实现enum

posted @ 2023-07-26 16:49  赋流  阅读(443)  评论(0编辑  收藏  举报