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
Unfortunately this is the well-established way to do this, although that
is a widespread naming convention for this
"copy".
You can also try:
db.User.findById('ABCD', this.foo.bind(this));
But this approach requires foo()
to have exactly the same signature as the one expected by findById()
(in your example you are skipping err
).