我有一些 JavaScript 代码,其中我有一个在函数外部声明的变量,但我似乎无法分配它。
我环顾四周,正在做普遍接受的在函数之外分配的事情,但仍然有问题。
有任何想法吗?
var numberPeopleSignedIn;
function setWaitTime(id, currentTimeToMinus){
var peopleAvailable = [];
hoodie.store.findAll('barber')
.done(function(object) {
object.forEach(function(barber) {
if (barber.statusInOut == "signedIn") {
peopleAvailable.push(barber);
}
numberPeopleSignedIn = peopleAvailable.length;
});
});
console.log(numberPeopleSignedIn); //This is returning undefined
}