Skip to content

Instantly share code, notes, and snippets.

@getify
Created May 28, 2016 22:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save getify/28c586cff83516cbd2dca573eb4cb194 to your computer and use it in GitHub Desktop.
Save getify/28c586cff83516cbd2dca573eb4cb194 to your computer and use it in GitHub Desktop.
Inline function expressions vs function declarations
function getOrderDetails(orderID,cb) {
db.find( "orders", orderID, function(err,order){
if (!err) {
db.find(
"customers",
order.customerID,
function(err,customer){
if (!err) {
order.customer = customer;
cb( null, order );
}
else cb(err);
}
);
}
else cb(err);
});
}
getOrderDetails( 1234, function(err,order){
if (!err) {
displayOrder(order);
}
else showError(err);
});
getOrderDetails( 1234, onOrderDetails );
// *************
function getOrderDetails(orderID,cb) {
db.find( "orders", orderID, onOrder );
// *************
function onOrder(err,order) {
if (!err) {
db.find( "customers", order.customerID, onCustomer );
}
else cb(err);
// *************
function onCustomer(err,customer){
if (!err) {
order.customer = customer;
cb( null, order );
}
else cb(err);
}
}
}
function onOrderDetails(err,order){
if (!err) {
displayOrder(order);
}
else showError(err);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment