I was wondering whether it would be ok to name the variable name for a promise just like the argument passed to a callback:
var dbItems = db.find();
dbItems.then(function(dbItems) {
// Do some stuff with dbItems here...
});
I think that would be syntactically correct, but are there any arguments (like possible confusion or readability) against using this from the perspective of code style?
var dbItems = db.find();
dbItems.then(function(dbItems) {
// Do some stuff with dbItems here...
});
Is the same thing as writing:
var dbItems = db.find();
dbItems.then(function(xxxxx) {
var dbItems = xxxxx;
// Do some stuff with dbItems here...
});
which means that inside the anonymous function, dbItems is a completely different thing, and you do not have access to the "outer" dbItems variable.
I don't usually recommend purchases on this site, but I feel that you could have very good use for this book. http://www.amazon.com/dp/0596517742