I've been messing around with using Node.js and CouchDB. What I want to be able to do is make a db call within an object. Here is the scenario that I am looking at right now:
var foo = new function(){
this.bar = null;
var bar;
calltoDb( ... , function(){
// what i want to do:
// this.bar = dbResponse.bar;
bar = dbResponse.bar;
});
this.bar = bar;
}
The issue with all of this is that the CouchDB callback is asynchronous, and "this.bar" is now within the scope of the callback function, not the class. Does anyone have any ideas for accomplishing what I want to? I would prefer not to have a handler object that has to make the db calls for the objects, but right now I am really stumped with the issue of it being asynchronous.