Enum

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

Verze ze dne 03. 11. 2019. Zobrazit nejnovější verzi.

Tento skript by neměl být instalován přímo. Jedná se o knihovnu, kterou by měly jiné skripty využívat pomocí meta příkazu // @require https://update.greatest.deepsurf.us/scripts/391854/746195/Enum.js

Autor
Gerrit
Verze
0.2
Vytvořeno
01. 11. 2019
Aktualizováno
03. 11. 2019
Size
2,4 KB
Licence
neuvedeno
// 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);