Enum

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

ของเมื่อวันที่ 03-11-2019 ดู เวอร์ชันล่าสุด

สคริปต์นี้ไม่ควรถูกติดตั้งโดยตรง มันเป็นคลังสำหรับสคริปต์อื่น ๆ เพื่อบรรจุด้วยคำสั่งเมทา // @require https://update.greasyforks.org/scripts/391854/746196/Enum.js

ผู้เขียน
Gerrit
เวอร์ชัน
0.2
สร้างเมื่อ
01-11-2019
อัปเดตเมื่อ
03-11-2019
Size
2.37 กิโลไบต์
สัญญาอนุญาต
ไม่มี

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"
长期地址
遇到问题?请前往 GitHub 提 Issues。