logo

/Code Snippet|v2.3.2

Class

new Enum(itemList)enum.jsline 68

Make a constant-list that has unique values.
In modern browsers (except IE8 and lower),
a value defined once can not be changed.

PARAMETERS
NameTypeDescription

itemList

stringArray.<string>

Constant-list (An array of string is available)

EXAMPLES
var Enum = require('tui-code-snippet/enum/enum'); // node, commonjs

var MYENUM = new Enum('TYPE1', 'TYPE2');
var MYENUM2 = new Enum(['TYPE1', 'TYPE2']);

//usage
if (value === MYENUM.TYPE1) {
     ....
}

//add (If a duplicate name is inputted, will be disregarded.)
MYENUM.set('TYPE3', 'TYPE4');

//get name of a constant by a value
MYENUM.getName(MYENUM.TYPE1); // 'TYPE1'

// In modern browsers (except IE8 and lower), a value can not be changed in constants.
var originalValue = MYENUM.TYPE1;
MYENUM.TYPE1 = 1234; // maybe TypeError
MYENUM.TYPE1 === originalValue; // true
*

Instance Methods

getName(value)enum.jsline 95

Return a key of the constant.

PARAMETERS
NameTypeDescription

value

number

A value of the constant.

RETURNS:
{

stringundefined

} - Key of the constant.

set(itemList)enum.jsline 78

Define a constants-list

PARAMETERS
NameTypeDescription

itemList

stringArray.<string>

Constant-list (An array of string is available)

Resizable