Enum

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

Pada tanggal 03 November 2019. Lihat %(latest_version_link).

Skrip ini tidak untuk dipasang secara langsung. Ini adalah pustaka skrip lain untuk disertakan dengan direktif meta // @require https://update.greasyfork.org/scripts/391854/746337/Enum.js

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

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.

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

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

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!)

Penulis
Gerrit
Versi
0.2
Dibuat
01 November 2019
Diperbarui
03 November 2019
Size
2,49 KB
Lisensi
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"