我正在尝试创建一个将通过使用类与Postgres数据库进行交互的类,但是在类中创建函数时会不断出错
我尝试将构造函数与原型一起使用,但仍然出现错误
/* eslint linebreak-style: ["error", "windows"] */
// eslint-disable-next-line no-unused-vars
const pool = require('../config/config.js');
// user constructor
class User {
constructor(user) {
this.username = user.username;
this.email = user.email;
this.password = user.password;
this.role = user.role;
}
// save new user in databes
function createUser() {
}
}
module.exports = User;
function createUser(params) {
^^^^^^^^^^
SyntaxError: Unexpected identifier
at new Script (vm.js:80:7)
at createScript (vm.js:274:10)
at Object.runInThisContext (vm.js:326:10)
at Module._compile (internal/modules/cjs/loader.js:664:28)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
at Module.load (internal/modules/cjs/loader.js:600:32)
at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
at Function.Module._load (internal/modules/cjs/loader.js:531:3)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)
这是正在得到的错误
答案 0 :(得分:0)
const pool = require('../config/config.js');
// user constructor
class User {
constructor(user) {
this.username = user.username;
this.email = user.email;
this.password = user.password;
this.role = user.role;
}
// save new user in database
createUser() {
}
}
module.exports = User;
正如其他人所提到的,这仅仅是一个语法问题。