Lexical scoping in a for loop enclosing a promise?
问题 I have an ids object, which maps id strings to product objects. for id of ids product = ids[id] console.log product # Prints out something different each loop. :) Product.create(product).then -> console.log product # Only prints out the last id each loop. :( I'm using a library for database interactions, which exposes promises (indicated by the then function above). I'm trying to print out the product variable inside the then function, but I only seem to be getting the last id in ids , so it