export class Queue<T> {
private _content: T[];
get content(): T[] {
if (!this._content) this._content = [];
return this._content;
}
}
上述ts代码经过creator打包后生成
System.register("chunks:///_virtual/Queue.ts", ["./rollupPluginModLoBabelHelpers.js", "cc"], function (e) {
var i, n;
return {
setters: [function (t) {
i = t.createClass
}, function (t) {
n = t.cclegacy
}],
execute: function () {
function t() {
this._content = void 0
}
n._RF.push({}, "63c74Jx+OxEGbmVuQEl43ax", "Queue", void 0), e("Queue", (i(t, [{
key: "content",
get: function () {
return this._content || (this._content = []), this._content
}
}]), t)), n._RF.pop()
}
}
})
通过如下代码 system.import
(function () {
System.import("chunks:///_virtual/Queue.ts").then(module => {
console.log(`Module loaded successfully: ${module}`);
}).catch(error => {
console.error('Failed to load module:', error);
});
})();
会出现引入失败,报错SystemJS Error#3 https://git.io/JvFET#3)
但是我把源码ts里面的get函数注释了再做上面打包再引入的操作 就可以正确访问Queue了,这个是什么原因呢? 这个get函数有什么问题呢,还有什么ts语法 写法会导致这种问题呢? 怎么避免?
get content(): T[] {
if (!this._content) this._content = [];
return this._content;
}