73c6533bf475cf801676942513edca165a6ed07f.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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) {
  23. for (var _len = arguments.length, param = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  24. param[_key - 1] = arguments[_key];
  25. }
  26. if (clazz["__Instance__"] == null) {
  27. clazz["__Instance__"] = new clazz(...param);
  28. }
  29. return clazz["__Instance__"];
  30. }
  31. });
  32. /**单例
  33. * 继承型,静止实例化
  34. */
  35. _export("Singleton", Singleton = class Singleton {
  36. /**
  37. * 获取实例
  38. */
  39. static getInstance() {
  40. var _class = this;
  41. if (!_class._instance) {
  42. _class._instantiateByGetInstance = true;
  43. _class._instance = new _class();
  44. _class._instantiateByGetInstance = false;
  45. }
  46. return _class._instance;
  47. }
  48. /**
  49. * 构造函数
  50. * @protected
  51. */
  52. constructor() {
  53. if (!this.constructor._instantiateByGetInstance) {
  54. throw new Error("Singleton class can't be instantiated more than once.");
  55. }
  56. }
  57. });
  58. // 实例
  59. Singleton._instance = void 0;
  60. // 是否是通过getInstance实例化
  61. Singleton._instantiateByGetInstance = false;
  62. _cclegacy._RF.pop();
  63. _crd = false;
  64. }
  65. };
  66. });
  67. //# sourceMappingURL=73c6533bf475cf801676942513edca165a6ed07f.js.map