what is correct way of writing this in js?
notice this.signals.total
is in a wrong context.
articleSchema.pre('save', function(next) {
if (!this.publisher) {
this.publisher = this.url;
}
social.facebook(this.url, function(err, signals) {
//problem is this
this.signals.total = signals.total_count;
});
if (!this.weight) {
this.weight = 1440;
}
var currentDate = new Date();
this.updated_at = currentDate;
if (!this.created_at) {
this.created_at = currentDate;
}
next();
});
this in that case refers to social.facebook
correct?
There are several ways I could deal with the problem, e.g. create outside variable, but what is js way?