* WeakRef Polyfill for ES2020 compatibility * * 为了兼容 Cocos Creator、Laya、微信小游戏等目标平台(仅支持 ES2020), * 提供 WeakRef 的 Polyfill 实现。 * * - 现代浏览器:自动使用原生 WeakRef (自动 GC) * - 旧环境:使用 Polyfill (无自动 GC,但 Scene 销毁时会手动清理)
| 21 | * - 旧环境:使用 Polyfill (无自动 GC,但 Scene 销毁时会手动清理) |
| 22 | */ |
| 23 | class WeakRefPolyfill<T extends object> implements IWeakRef<T> { |
| 24 | private _target: T; |
| 25 | |
| 26 | constructor(target: T) { |
| 27 | this._target = target; |
| 28 | } |
| 29 | |
| 30 | deref(): T | undefined { |
| 31 | return this._target; |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * WeakRef 构造函数类型 |
nothing calls this directly
no outgoing calls
no test coverage detected