123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- System.register(["cc"], function (_export, _context) {
- "use strict";
- var _cclegacy, Instance, Singleton, _crd;
- _export({
- default: void 0,
- Singleton: void 0
- });
- return {
- setters: [function (_cc) {
- _cclegacy = _cc.cclegacy;
- }],
- execute: function () {
- _crd = true;
- _cclegacy._RF.push({}, "f298auxhOZIcJjqKwn1kGP+", "Instance", undefined);
- /**单例
- * 加方法型
- * public static getInstance(): XXX{
- return Instance.get(XXX);
- }
- */
- _export("default", Instance = class Instance {
- static get(clazz, ...param) {
- if (clazz["__Instance__"] == null) {
- clazz["__Instance__"] = new clazz(...param);
- }
- return clazz["__Instance__"];
- }
- });
- /**单例
- * 继承型,静止实例化
- */
- _export("Singleton", Singleton = class Singleton {
- /**
- * 获取实例
- */
- static getInstance() {
- const _class = this;
- if (!_class._instance) {
- _class._instantiateByGetInstance = true;
- _class._instance = new _class();
- _class._instantiateByGetInstance = false;
- }
- return _class._instance;
- }
- /**
- * 构造函数
- * @protected
- */
- constructor() {
- if (!this.constructor._instantiateByGetInstance) {
- throw new Error("Singleton class can't be instantiated more than once.");
- }
- }
- });
- // 实例
- Singleton._instance = void 0;
- // 是否是通过getInstance实例化
- Singleton._instantiateByGetInstance = false;
- _cclegacy._RF.pop();
- _crd = false;
- }
- };
- });
- //# sourceMappingURL=73c6533bf475cf801676942513edca165a6ed07f.js.map
|