I find myself assigning this to a variable so I can easily use it in callbacks and closures.
Is this bad practice? Is there a better way of referring back to the original function?
Here is a typical example.
User.prototype.edit = function(req, res) {
var self = this,
db = this.app.db;
db.User.findById('ABCD', function(err, user)) {
// I cannot use this.foo(user)
self.foo(user);
});
};
User.prototype.foo = function(user) {
};
Do you normally use this approach or have you found a cleaner solution?