问题:现有一个通用的模块,想加入以前开发若干游戏,发现有一个基础类会类名冲突。
解决方案1: import 类名 as 别名 在预览时候不报错,cocos 发布过后出错
解决方案2: 使用namespace命名空间 同一命名空间且文件不同无法调用
问问大家有什么解决方案。
引入自定义命名空间后 Object prototype may only be an Object or null: undefined
class App {
get 模块(){
return 你的模块
}
}
declare global {
interface Window {
app: App
}
const $app: App
}
window.$app = new App()
使用$app.模块来调用
类1
namespace AiWan
{
export class Singleton1{
static Instance<T extends {}>(this: new () => T): T {
if(!(<any>this).instance){
(<any>this).instance = new this();
}
return (<any>this).instance;
}
}
}
类2
///
namespace AiWan
{
export class Test1 extends Singleton1 {
test()
{
console.log("test12");
}
}
}
编辑器报错 load script [./assets/Script/Test1] failed : ReferenceError: Singleton1 is not defined