javascript - 调用我的打字稿对象的新实例时的非法构造函数
问题描述
我有一个自定义打字稿类对象:
class IndexedDBManager {
constructor(autoCreateDatabaseAndTable : boolean = false, databaseName : string = null, tableName : string = null, primaryKey : string = null, obtrusiveError: boolean = false) {
if (!this.VerifyIndexDB()) {
console.error("IndexedDB is not supported on this browser.");
if (obtrusiveError) {
alert("IndexedDB is not supported on this browser.");
return;
}
}
if (autoCreateDatabaseAndTable) {
this.SetAndCreateDatabase(databaseName, obtrusiveError);
this.SetAndCreateTable(tableName, primaryKey, obtrusiveError);
}
}
...
}
当尝试使用实例化此类的新实例时
var myTest = new IndexedDBManager(true, "myTestDB", "myTestTable", "key", true);
在浏览器控制台中,我收到以下控制台错误:
TypeError: Illegal constructor.
这是怎么回事,我该如何解决?
编辑:如评论中所述,从构造函数中删除所有代码并不能解决问题。
解决方案
推荐阅读
- java - 如何移动收藏
大于 0 的值到小数位 - reactjs - 如何在 react-data-grid 中实现撤消/重做?
- parallel-processing - 同一块中的线程是否按顺序执行?
- ios - 如何在 uilabel 上实现左对齐(与本机键盘中出现的建议相同)?
- javascript - Typescript - 输入数组方法
- docker - noVNC Docker 与 Jmeter - 启动按钮错误,无法创建脚本记录器 - keytool 错误:java.security.ProviderException
- json - 如何修复 JSON 重复密钥?
- vue.js - Vue JS:从数据库中获取数据时传递路由参数
- arrays - 反应钩子无法读取未定义的属性映射
- c# - asp.net 核心种子数据