Enum

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

目前为 2019-11-03 提交的版本。查看 最新版本

此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.cn-greasyfork.org/scripts/391854/746195/Enum.js

作者
Gerrit
版本
0.2
创建于
2019-11-01
更新于
2019-11-03
大小
2.4 KB
许可证
暂无
// Usage Example 1
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.assert(col + "");    // "green"
console.assert(col * 1);     // "1"

// Usage Example 2
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"

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