javascriptnaming-conventionsjshint

Javascript ENUM pattern naming convention


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

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

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 also outputs the following warning:

Missing 'new' prefix when invoking a constructor.

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.


Solution

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

    As requested here is a link.