我试图通过枚举访问地图的值,并为其中的所有字符串创建一个翻译就绪的应用程序.两个问题都重叠,我必须决定使用枚举还是只使用JSON格式的对象.
那么枚举和对象之间的区别和用途到底是什么?
例如:
const enum FieldNames {
FirstField: "Field One",
SecondField: "Field Two"
};
someFieldArray[FieldNames.FirstField].label = FieldNames.FirstField;
someFieldArray[FieldNames.SecondField].label = FieldNames.SecondField;Run Code Online (Sandbox Code Playgroud)
const FieldNames = {
FirstField: "Field One",
SecondField: "Field Two"
};
someFieldArray[FieldNames.FirstField].label = FieldNames.FirstField;
someFieldArray[FieldNames.SecondField].label = FieldNames.SecondField;Run Code Online (Sandbox Code Playgroud)
我真的没有从简单对象中选择枚举的好处.在我看来,一个对象有更多的好处,没有任何缺点.