我不仅到处看,而且找不到答案。我找到了这个mongoose-model-ES6。我正在尝试使用Symbol data type.,所以上一个链接无济于事。
我的课看起来像这样
import mongoose from 'mongoose';
const _user_key = Symbol('key');
const _user_name = Symbol('name');
const _user_email = Symbol('email');
class User extends mongoose.Schema {
constructor(key,name,email) {
const user = super({
this[_user_key] = key;
this[_user_name] = name;
this[_user_email] = email;
})
}
get key () {return this[_user_key]};
get name (){return this[_user_name]};
get email () {return this[_user_email]};
};
export default mongoose.model('User', new User);
我从航站楼跑
this[_user_key] = key;
^
SyntaxError: Unexpected token '['
at Loader.moduleStrategy (internal/modules/esm/translators.js:122:18)
at async link (internal/modules/esm/module_job.js:42:21)
如果我尝试Bergi的建议
class User extends mongoose.Schema {
constructor(key,name,email) {
const user = super(
this[_user_key] = key;
this[_user_name] = name;
this[_user_email] = email;
)
}
我出错了
this[_user_key] = key;
^^^
SyntaxError: missing ) after argument list
答案 0 :(得分:1)
该错误看上去与符号无关,但与实际语法错误
你的意思是
super({
[_user_key] : key,
[_user_name] : name,
[_user_email] : email,
})
?