A strange node.js construction. How about the references?
What about code like below. Since there are two functions 'open', but only
one is ever called, what about implicit references?
cbe = cbError
cbs = cbSuccess
This one is only useful if you do something with the error or data.
function getItem(id, cbe, cbs){
DB.getItem(id, function(e){
cbe(doSomething(e));
}, function(data){
cbs(doSomething(data));
});
}
If you don't touch the error you could just do:
function getItem(id, cbe, cbs){
DB.getItem(id, cbe, function(data){
cbs(doSomething(data));
});
}
If you don't touch the data you could just do:
function getItem(id, cbe, cbs){
DB.getItem(id, function(e){
cbe(doSomething(e));
}, cbs);
}
If you don't touch the data and error you could just do:
function getItem(id, cbe, cbs){
DB.getItem(id, cbe, cbs);
}
Now an async callback chain:
function getItems(id, cbe, cbs){
DB1.getItem(id, cbe, function(data1){
DB2.getItem(id, cbe, function(data2){
DB3.getItem(id, cbe, function(data3){
cbs(data1, data2, data3);
});
});
});
}
So you see the effect, no if (err) cb(e)
I split errors immediately inside the db.method.
if (e) cbe(e) else cbs(data);
So what you think?
No comments:
Post a Comment