Enum

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

Per 03-11-2019. Zie de nieuwste versie.

Dit script moet niet direct worden geïnstalleerd - het is een bibliotheek voor andere scripts om op te nemen met de meta-richtlijn // @require https://update.greasyfork.org/scripts/391854/746196/Enum.js

Maker
Gerrit
Versie
0.2
Gemaakt op
01-11-2019
Bijgewerkt op
03-11-2019
Grootte
2,37 KB
Licentie
N.v.t.

Usage Examples


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.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(col.name);       // "BLUE"
console.log(col.text);       // ""
console.assert(col.ordinal); // "2"

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



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

console.log(FLAGS.FOURTH | FLAGS.SECOND); // "10"