I looked everywhere not only SO,but couldn't find the answer. I found this mongoose-model-ES6. I am trying to use Symbol data type. so the previous link does not help.
My class looks like this
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);
I run from terminal
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)
If I try what Bergi suggested
class User extends mongoose.Schema {
constructor(key,name,email) {
const user = super(
this[_user_key] = key;
this[_user_name] = name;
this[_user_email] = email;
)
}
I got error
this[_user_key] = key;
^^^
SyntaxError: missing ) after argument list
The error does not look related to symbols but to an actual syntax error
Did you mean
super({
[_user_key] : key,
[_user_name] : name,
[_user_email] : email,
})
?
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加