cione-comp-lib
Version:
`$ yarn add cione-comp-lib` 或者 `$ npm i cione-comp-lib -S`
43 lines (42 loc) • 1.14 kB
JavaScript
var wmUniqueIndex = Math.round(Math.random() * 9);
var supportDefineProperty = typeof Object.defineProperty === "function";
var WeakMap = function() {
function WeakMap2() {
this._id = "__ec_inner_" + wmUniqueIndex++;
}
WeakMap2.prototype.get = function(key) {
return this._guard(key)[this._id];
};
WeakMap2.prototype.set = function(key, value) {
var target = this._guard(key);
if (supportDefineProperty) {
Object.defineProperty(target, this._id, {
value,
enumerable: false,
configurable: true
});
} else {
target[this._id] = value;
}
return this;
};
WeakMap2.prototype["delete"] = function(key) {
if (this.has(key)) {
delete this._guard(key)[this._id];
return true;
}
return false;
};
WeakMap2.prototype.has = function(key) {
return !!this._guard(key)[this._id];
};
WeakMap2.prototype._guard = function(key) {
if (key !== Object(key)) {
throw TypeError("Value of WeakMap is not a non-null object.");
}
return key;
};
return WeakMap2;
}();
var WeakMap$1 = WeakMap;
export { WeakMap$1 as default };