import Log from "../Log"; /** * 基类、单例 */ export default class Provider { protected readonly className: string = 'Provider'; private static instance; private static readonly pool = {}; constructor() { } public static getInstance(this: T): InstanceType { // return this.instance ||= new this(); if (!this.instance) { let startTime = performance.now(); this.instance = new this(); let thatName = this.instance.getClassName() || this.name; Log.info('实例已创建,', thatName, this.instance, '耗时' + ((performance.now() - startTime) | 0) + 'ms'); Provider.pool[thatName] = this.instance; } return this.instance; } public static getPool() { return { pool: Provider.pool, } } }