export function weakBind(callable, thisObject) {
let wrapper = new WeakRef(thisObject);
return function(...args) {
let unwrapped = wrapper.deref();
if (unwrapped)
callable.apply(unwrapped, args);
};
}
export function weakNew(constructor) {
let wrapper = null;
return function() {
let instance = wrapper?.deref();
if (!instance) {
instance = constructor();
wrapper = new WeakRef(instance);
}
return instance;
};
}