If queryDB is asynchronous, it is good advice (especially if you are using jQuery) for queryDB and hence getPerson (with modification to your code) to return a "promise" type object. From that promise you can attach more success/failure/completed type callbacks to continue processing. In jQuery, those kid of callbacks can be done with done, fail, always as in:
var person = new ObjPerson;
var userDataPromise = ObjPerson.getPerson();
userDataPromise.done(function(person){
//deal with person object here
//
}).fail(function(errorobj){
//deal with error
}).always(function(){
//deal with completion
});
Now, if you were using the jQuery library, you could return the promise returned in the ajax call. That's not what I'll advise. In all likelihood, you have some strict requirements about how your person is to be invoked. Furthermore, you really don't care to have other parts of your code know that you're doing ajax or localDB or anything... they just need access to the person.
So here's a rough sketch about how you can complete your code to do that.
function ObjPerson() {
function getData (args,success,fail){
//somehow get your data. We'll assume it doesn't return promises
}
this.getPersonPromise = function() {
var returnedPromise = $.Deferred();
getData(args,function(data){
//success callback
//process data (assume PersonCustomData is defined elsewhere)
var person = new PersonCustomData (data)
returnedPromise.resolve(person);
}, function(error) {
//failure callback, return custom errors, or maybe
//just return original error if lazy or don't quite know all methods
//of failure or something.
var errorObj = ...
returnedPromise.reject(errorObj);
});
return returnedPromise;
}
}
var person = new ObjPerson;
var promise = ObjPerson.getPersonPromise();
person.done(function(person){
//do more stuff with PersonCustomData instance
}).fail(function(errorObj){
//oops
})
etc. That way you do not have to pass around callbacks until after the fact. Very cool.