Javascript ENUM模式命名约定 [英] Javascript ENUM pattern naming convention

查看:88
本文介绍了Javascript ENUM模式命名约定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个JavaScript项目,该项目需要使用javascript"Enums",意思是对象,例如:

I am working on a javascript project which requires use of javascript "Enums" meaning Objects like:

var WinnerEnum = {
            Player1: 1,
            Player2: 2,
            Draw: 0
    };

这对我来说非常有用,但是,我不知道(按惯例)命名Enum的正确方法是什么,因为据我所知,只有类名以大写字母开头(表示调用的能力)的构造函数).

This is working great for me, however, I have no idea what is the proper way (according to convention) to name the Enum because as far as I know only class names start with a capital letter (indicating the ability to call a constructor on).

JSHint还输出以下警告:

JSHint also outputs the following warning:

Missing 'new' prefix when invoking a constructor.

如果没有约定,我将不介意将枚举与类名混淆的一种好方法. 更新2014年:JSHint不再这样做.

If there is no convention, I would appreciate a good way to name enums that would not confuse them with class names. Update 2014 : JSHint no longer does this.

推荐答案

根据Google的编码约定,这实际上是在javascript中命名枚举的正确方法.

According to Google's coding conventions this is the correct way indeed to name an enum in javascript.

根据要求此处是链接.

这篇关于Javascript ENUM模式命名约定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆