Enum

Enumeration class. Each enum propertiy has the properties "ordinal", "name" and "text".

As of 03.11.2019. See ბოლო ვერსია.

ეს სკრიპტი არ უნდა იყოს პირდაპირ დაინსტალირებული. ეს ბიბლიოთეკაა, სხვა სკრიპტებისთვის უნდა ჩართეთ მეტა-დირექტივაში // @require https://update.greasyforks.org/scripts/391854/746332/Enum.js.

ავტორი
Gerrit
ვერსია
0.2
შექმნილია
01.11.2019
განახლებულია
03.11.2019
Size
2,49 KB
ლიცენზია
პ/გ

Usage Examples


class COLOR extends Enum {};
COLOR.init([ { "RED": "red" }, { "GREEN": "green" }, { "BLUE": "blue" } ]);
let col = COLOR.GREEN;

console.log(COLOR.GREEN.name);       // "GREEN"
console.log(COLOR.GREEN.text);       // "green"
console.assert(COLOR.GREEN.ordinal); // "1"

console.log(col[1] === COLOR.GREEN); // "true"

console.assert(col + ""); // "green"
console.assert(col * 1);  // "1"



class COLOR extends Enum {};
COLOR.init([ "RED", "GREEN", "BLUE" ]);

console.log(COLOR[2].name)            // "BLUE"
console.log(COLOR[2].text);           // ""
console.log(COLOR[2].ordinal);        // "2"

console.log(COLOR[2] === COLOR.BLUE); // "true"

console.log(col + ""); // "BLUE"
console.log(col * 1)   // "2"



class FLAGS extends Enum {};
FLAGS.init([ "FIRST", "SECOND", "THIRD", "FOURTH"], 1, ord => ord<<1);

console.log(FLAGS.FOURTH | FLAGS.SECOND); // "10"
长期地址
遇到问题?请前往 GitHub 提 Issues。