Enum

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

אין להתקין סקריפט זה ישירות. זוהי ספריה עבור סקריפטים אחרים // @require https://update.greasyfork.org/scripts/391854/746956/Enum.js

יוצר
Gerrit
גרסה
0.3
נוצר
01-11-2019
עודכן
05-11-2019
רישיון
לא זמין

Usage

Object initialization

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"

Array initialization

const COLORS = class COLOR extends Enum {}.init([ "RED", "GREEN", "BLUE" ]); console.log(COLORS[2].name) // "BLUE" console.log(COLORS[2].text); // "" console.log(COLORS[2].ordinal); // "2" console.log(COLORS[2] === COLORS.BLUE); // "true" console.log(COLORS.BLUE + ""); // "BLUE" console.log(COLORS.BLUE * 1); // "2"

Ordinal value generator

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