javascript - 扩展类 SharedArrayBuffer 导致“构造函数 SharedArrayBuffer 需要‘新’”
问题描述
我正在尝试扩展SharedArrayBuffer
该类以轻松传递组件数据以在工作线程中使用,因为我们每秒处理数万个实体。这是我目前的代码。
export default abstract class Component extends SharedArrayBuffer {
public name: String;
public data: DataView;
public constructor(size) {
super(size);
this.data = new DataView(this);
this.name = this.constructor.name.toLowerCase();
}
}
然后我有一个扩展抽象类组件的组件,称为Position
.
export default class Position extends Component {
public constructor(x: number = 0, y: number = 0, layer: number = 0) {
super(12);
this.data.setUint32(0, x);
this.data.setUint32(4, y);
this.data.setUint32(8, layer);
}
get x() { return this.data.getUint32(0); }
set x(value: number) { this.data.setUint32(0, value); }
get y() { return this.data.getUint32(4); }
set y(value: number) { this.data.setUint32(4, value); }
get layer() { return this.data.getUint32(8); }
set layer(value: number) { this.data.setUint32(8, value); }
}
通过创建 Position 组件时,new Position(...)
我收到以下错误:
Component.js:19 var _this = _super.call(this, size) || 这个; ^
TypeError:构造函数 SharedArrayBuffer 需要“新”
您可以在下面找到从 TypeScript 代码创建的 JavaScript。
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var Component = /** @class */ (function (_super) {
__extends(Component, _super);
function Component(size) {
var _this = _super.call(this, size) || this;
_this.data = new DataView(_this);
_this.name = _this.constructor.name.toLowerCase();
return _this;
}
return Component;
}(SharedArrayBuffer));
exports.default = Component;
确保在super
执行时调用 SharedArrayBuffer 的构造函数以防止此错误的最佳方法是什么?
解决方案
推荐阅读
- python - 如何根据数据框中的列条件应用函数
- javascript - 我需要将表格中输入的数据捕获为角度的 JSON
- javascript - 无法从 React-Native-Firebase(v6) Firestore 获取数据:未定义不是函数(在 '...this._firestore.native.collectionGet...' 附近)
- javascript - 角度库导入 *
- python - 从 requirements.txt 中安装车轮
- arrays - NullReferenceException vb 数组
- git - 数据工厂发布管道问题
- android - 从 imageView 分享 GIF 到 Whatsapp
- aws-cdk - 使用 CDK 创建 AWS EC2 实例后如何获取公共 DNS?
- python - 在矩阵的对角线上添加所有单词的迭代