const funcCache = {};
export async function _callFunction(funcName: string, ...args: any[]) {
try {
if (!funcCache[funcName]) {
let context = (typeof window !== 'undefined') ? window : global;
funcCache[funcName] = context[funcName];
}
let func = funcCache[funcName];
if (typeof func === 'function') {
let result = await func(...args);
if (result instanceof Promise) result = await result;
return result;
} else {
console.log(`${funcName} 不存在!`);
}
} catch (err) {
console.log(`Calling ${funcName} failed: ${err.message}`);
}
}