58030cb831be254673c71416980e82012218db57.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. System.register(["cc"], function (_export, _context) {
  2. "use strict";
  3. var _cclegacy, Instance, Singleton, _crd;
  4. _export({
  5. default: void 0,
  6. Singleton: void 0
  7. });
  8. return {
  9. setters: [function (_cc) {
  10. _cclegacy = _cc.cclegacy;
  11. }],
  12. execute: function () {
  13. _crd = true;
  14. _cclegacy._RF.push({}, "f298auxhOZIcJjqKwn1kGP+", "Instance", undefined);
  15. /**单例
  16. * 加方法型
  17. * public static getInstance(): XXX{
  18. return Instance.get(XXX);
  19. }
  20. */
  21. _export("default", Instance = class Instance {
  22. static get(clazz, ...param) {
  23. if (clazz["__Instance__"] == null) {
  24. clazz["__Instance__"] = new clazz(...param);
  25. }
  26. return clazz["__Instance__"];
  27. }
  28. });
  29. /**单例
  30. * 继承型,静止实例化
  31. */
  32. _export("Singleton", Singleton = class Singleton {
  33. /**
  34. * 获取实例
  35. */
  36. static getInstance() {
  37. const _class = this;
  38. if (!_class._instance) {
  39. _class._instantiateByGetInstance = true;
  40. _class._instance = new _class();
  41. _class._instantiateByGetInstance = false;
  42. }
  43. return _class._instance;
  44. }
  45. /**
  46. * 构造函数
  47. * @protected
  48. */
  49. constructor() {
  50. if (!this.constructor._instantiateByGetInstance) {
  51. throw new Error("Singleton class can't be instantiated more than once.");
  52. }
  53. }
  54. });
  55. // 实例
  56. Singleton._instance = void 0;
  57. // 是否是通过getInstance实例化
  58. Singleton._instantiateByGetInstance = false;
  59. _cclegacy._RF.pop();
  60. _crd = false;
  61. }
  62. };
  63. });
  64. //# sourceMappingURL=58030cb831be254673c71416980e82012218db57.js.map