最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Chrome error: 'unknown message reserved_word' on JavaScript enum declaration - Stack Overflow

programmeradmin3浏览0评论
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!

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!

Share Improve this question asked Jun 20, 2012 at 12:38 user1436713user1436713 852 silver badges6 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

You need to do something like:

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

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

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 :)).

发布评论

评论列表(0)

  1. 暂无评论