Greasy Fork is available in English.
symbol-like object with initialValue to create private fields
当前为
此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.greasyfork.icu/scripts/391608/743901/PrivateFieldAccessor.js
// ==UserScript==
// @name PrivateFieldAccessor
// @namespace hoehleg.userscripts.private
// @version 0.1
// @description symbol-like object with initialValue to create private fields
// @author Gerrit Höhle
// @grant none
// ==/UserScript==
/* jshint esversion: 6 */
const PrivateFieldAccessor = (() => {
'use strict';
return class PrivateFieldAccessor {
constructor(description, initialValue) {
this.symbol = Symbol(description);
this.initialValue = initialValue;
}
init(object) {
object[this] = this.initialValue;
}
get(object) {
return object[this];
}
valueOf() {
return this.symbol;
}
toString() {
return this.symbol.description;
}
};
})();