You only need callbacks if you are making asynchronous non-blocking calls.
var string = "foo",
new_string = enrich(foo);
doStuff(new_string);
Safe if enrichblocked. for instance
function enrich(str) {
return str;
}
blocks, so it's safe to do it. Where
function enrich(str) {
return str;
}
Uses non-blocking IO and is not safe. What you want to do is:
function enrich(str, cb) {
return cb(str);
}
var string = "foo",
new_string = enrich(foo, function (str) {
doStuff(new_string);
});
note that
enriched = enrichString(regular, sys.puts(data));
It does not work because you pass the return value sys.puts(data)as your parameter to the function (data is undefined too!)
You need to pass a function.