refactor: polyfills review

This commit is contained in:
dongchengjie
2024-05-30 20:27:12 +08:00
parent 3514cfbd44
commit 01d67eb239
6 changed files with 79 additions and 93 deletions

View File

@@ -1,33 +1,16 @@
(function (global) {
if (typeof global === "object" && global) {
if (typeof global["WeakRef"] === "undefined") {
global.WeakRef = (function (wm) {
function WeakRef(target) {
wm.set(this, target);
}
WeakRef.prototype.deref = function () {
return wm.get(this);
};
return WeakRef;
})(new WeakMap());
}
(function () {
if (typeof window.WeakRef !== "undefined") {
return;
}
})(
(function () {
switch (true) {
case typeof globalThis === "object" && !!globalThis:
return globalThis;
case typeof self === "object" && !!self:
return self;
case typeof window === "object" && !!window:
return window;
case typeof global === "object" && !!global:
return global;
case typeof Function === "function":
return Function("return this")();
window.WeakRef = (function (weakMap) {
function WeakRef(target) {
weakMap.set(this, target);
}
return null;
})()
);
WeakRef.prototype.deref = function () {
return weakMap.get(this);
};
return WeakRef;
})(new WeakMap());
})();