我认为写入数据库需要时间这一事实使得此函数未定义。我对吗?如果是这样,程序员如何在数据库调用的回调中避免使用百万个嵌套函数?
function createStripeCustomer(email) {
stripe.customers.create({
email: email
},
function (err, customer) {
if (err) {
console.log('The stripe error is ', err);
}
console.log('The created customer id is ', customer.id); // This works
return customer.id; // we know customer.id works because it shows up in console
}
);
}
出于某种原因,这给出了undefined:
var getCustomerId = createStripeCustomer(req.body.email);
console.log ('This should say the id but it says undefined: ', getCustomerId);