我发现很多与.default相关的错误都不是构造函数,但我不明白在这种情况下默认是什么。我无法在文档indeed there is a page on the default keyword on MDN中找到有关它的任何信息,但它并不是我所指的。
我所指的默认值是在错误消息中注明,例如
_Db2.default不是构造函数
另外,为什么_Db2
被引用?在控制台中我测试了是否有_Db并且存在。 _Db === _Db2
是真的。这是为什么?
注意:我们正在使用babel从es6转换为commonjs
修改
导入示例
import Db from '../localstorage/db/Db';
const db = new Db(); //error is thrown here
Db看起来有点像这样
import Realm from 'realm';
export default function Db() {
this.realm = new Realm({
schema: [Wallet, WalletAddress, WalletTransaction, Log, APIWallet, APITransaction, APIAccount, Configuration],
path: config.db_path
});
logger(2, realm.path);
}
Db.prototype.doOneToMany = function(one, many) {..};
Db.prototype.query = function(model, filter) {..};
Db.prototype.insert = function(model, options) {..};
Db.prototype.del = function(model, obj) {..};
Db.prototype.update = function(obj, options) {..};
Db.prototype.write = function(func) {..};
Db.prototype.close = function() {..};