在此函数调用上获取未定义

时间:2015-01-20 21:16:09

标签: javascript

我认为写入数据库需要时间这一事实使得此函数未定义。我对吗?如果是这样,程序员如何在数据库调用的回调中避免使用百万个嵌套函数?

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);

0 个答案:

没有答案