4
enum ButtonType { Autowoot, Autoqueue }

Is causing Google Chrome's developer tools to give me this error:

Uncaught SyntaxError: <unknown message reserved_word>

I read that you can create enumerations like that from here, but my script doesn't run because of this error here. I'm doing exactly what that person who answered the question wrote, and it doesn't function. Any ideas?

Thanks!

4

2 回答 2

3

You need to do something like:

var ButtonType = {
  'Autowoot' : 0,
  'Autoqueue' : 1
};

The enum syntax enum ButtonType { Autowoot, Autoqueue } is not supported currently.

于 2012-06-20T12:44:56.613 回答
3

JavaScript doesn't do static typing of variables.

Once a variable has been declared, it's data may be anything that's a valid JavaScript construct. (Well, really, everything is pretty much an object).

enum ButtonType = {'Autowoot':0, 'Autoqueue':1};

Is giving an error because enum is a javascript reserved word marked for future usage. You can't use it, but it does nothing.

If you're trying to declare an object called ButtonType in the current execution scope, you should do as @xdazz said:

var ButtonType = {'Autowoot':0, 'Autoqueue':1};

(If you want it in another scope, that's a different question though :)).

于 2012-06-20T12:51:58.910 回答