- Home /
Question by
Hardstop · Jul 26, 2014 at 02:30 AM ·
javascriptlistenuminsert
Javascript Enum Write List
enum Item
{
ID,
Name
};
var pItem : Item;
function Start ()
{/*
Item apple = new Item();
apple.ID = 1;
apple.Name = "Apple";*/
var apple;
pItem.ID = 1;
pItem.Name = "Apple";
}
Editor tells me that the fields are read only, why is that?
Comment
Best Answer
Answer by Eric5h5 · Jul 26, 2014 at 03:47 AM
You seem to be confusing enums with classes. Enums are just a way of avoiding magic numbers by using words that represent numbers. You never use "new" with them or try to assign values like that. If you want to do that then you'd make a class.
P.S. Also never do things like "var apple;"...you must always define the type, either explicitly, or implicitly by declaring a value.
Your answer
![](https://koobas.hobune.stream/wayback/20220613155010im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Help with C#(Sharp) to Java Script :) !!! 1 Answer
Insert enum breaking existing inspector values 2 Answers
How to find the opposite variables list? 1 Answer
Create Enumeration from List 0 Answers