Enum

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

Version vom 03.11.2019. Aktuellste Version

Dieses Skript sollte nicht direkt installiert werden. Es handelt sich hier um eine Bibliothek für andere Skripte, welche über folgenden Befehl in den Metadaten eines Skriptes eingebunden wird // @require https://update.greasyfork.org/scripts/391854/746337/Enum.js

Du musst eine Erweiterung wie Tampermonkey, Greasemonkey oder Violentmonkey installieren, um dieses Skript zu installieren.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

Sie müssten eine Skript Manager Erweiterung installieren damit sie dieses Skript installieren können

(Ich habe schon ein Skript Manager, Lass mich es installieren!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

Autor
Gerrit
Version
0.2
Erstellt am
01.11.2019
Letzte Aktualisierung
03.11.2019
Größe
2,49 KB
Lizenz
n/a

Usage Examples


const COLORS = class COLOR extends Enum {}.init({ 
    "RED": "red" ,
    "GREEN": "green" , 
    "BLUE": "blue"
});
console.log(COLORS[0] === COLORS.RED);   // "true"
console.log(COLORS[1] === COLORS.GREEN); // "true"
console.log(COLORS[2] === COLORS.BLUE);  // "true"

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

console.assert(COLORS.GREEN + ""); // "green"
console.assert(COLORS.GREEN * 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(COLOR.BLUE + "");         // "BLUE"
console.log(COLOR.BLUE * 1);          // "2"



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

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