Answer the question
In order to leave comments, you need to log in
How not to repeat the same action in methods?
There is a constructor, and all prototype methods start the same way:
function DB() {
}
DB.prototype.add = function (req, res, next) {
Token.findOne({token: req.token}, function(err, token) {
.....
.....
})
}
DB.prototype.addToSource = function (req, res, next) {
Token.findOne({token: req.token}, function(err, token) {
.....
.....
})
}
// остальние методы
module.exports = new DB;
Answer the question
In order to leave comments, you need to log in
I think that approximately in this direction to act. Maybe missed something
function DB() {
this.token = function(req) {
return Token.findOne({token: req.token}, function(err, token) {
.....
.....
})
}
}
DB.prototype.add = function (req, res, next) {
var token = this.token(req);
}
DB.prototype.addToSource = function (req, res, next) {
var token = this.token(req);
}
// остальние методы
module.exports = new DB;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question