Enum

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

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

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

ავტორი
Gerrit
ვერსია
0.2
შექმნილია
01.11.2019
განახლებულია
03.11.2019
Size
2,37 KB
ლიცენზია
პ/გ
// Usage Example 1
class COLOR extends Enum {};
COLOR.init([ { "RED": "red" }, { "GREEN": "green" }, { "BLUE": "blue" } ]);
let col = COLOR.GREEN;

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

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

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

console.log(col.name);       // "BLUE"
console.log(col.text);       // ""
console.assert(col.ordinal); // "2"

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

// Usage Example 3
class FLAGS extends Enum {};
FLAGS.init([ "FIRST", "SECOND", "THIRD", "FOURTH"], 1, ord => ord<<1);
console.log(FLAGS.FOURTH | FLAGS.SECOND);