TS单例模式的模块化导出

class Share {
    private constructor() {};
    private static instance: Share = null;

    public static getInstance(): Share {
        this.instance = this.instance || new Share();
        return this.instance;
    };
}
module.exports = Share.getInstance();
conset Share = require('Share')

 

class GSVarbiles {
    private constructor() { };
    private static instance: GSVarbiles = null;

    public static getInstance(): GSVarbiles {
        this.instance = this.instance || new GSVarbiles();
        return this.instance;
    };
    public a = 1;
}
export default GSVarbiles.getInstance();
import GSVarbiles from './GSVarbiles'

 全局导出

let GData = new class {

}();
window['GData'] = GData;

 

 

你可能感兴趣的:(Cocos)