如何在类括号内定义变量? 这是我的代码:
var connection = require('../config/db.js');
var q = require('q');
var dfd = q.defer();
class M_Profil{
constructor(){}
getDataProfil(params){
connection.query("SELECT * FROM user WHERE id_user = ?", [params], function(err, rows, fields){
if (err){
return dfd.reject(err);
}
return dfd.resolve(rows[0]);
});
return dfd.promise;
}
}
控制器:
class C_Profil{
constructor(){}
profil_get(req, res, next) {
m_profil.getDataProfil(req.user.id_user)
.then(function(result){
if (result) {
res.render("manajemen_profil/manajemen_profil", {
person: req.user,
user: result,
message_err: req.flash('message_err'),
message_success: req.flash('message_success'),
notif: req.session.notif
});
}
else{
req.flash('message_err', "Id user not found");
res.redirect('/');
}
})
.catch(function(err){
req.flash('message_err', err);
res.redirect('/');
});
}
}
当我在类括号中声明变量connection,q和dfd时返回错误。那么如果我想在M_Profil类中扩展属性呢?