-
-
Save getify/28c586cff83516cbd2dca573eb4cb194 to your computer and use it in GitHub Desktop.
Inline function expressions vs function declarations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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