I am curious what is considered the better style/the correct way to do something.
In javascript, I could do the following:
function one() {
two(param, function(ans){
// do more work
});
}
function two(param, callback) {
var answer;
//do work
callback(answer);
}
but I could have a similar result by simply returning the answer:
function one() {
var ans = two(param);
// do more work
}
function two(param, callback) {
var answer;
//do work
return answer;
}
I think that if all you need is "answer" then it is probably better to use the second version and just return that value rather than passing a callback function as a parameter, etc. - is my thinking correct? Any ideas on the relative performance of the two? Again, I would expect the return version to be better performance-wise.