当我在数组上调用pop()
函数时,NodeJS出现了一个奇怪的错误: TypeError: cars.pop不是一个函数
。我感到困惑。
有人能提供帮助吗?以下是代码。谢谢:
//callback chaining to avoid having multiple callbacks in the event queue
//only one callback calling others
function showCar(car, callback) {
console.log('Saw a ' + car);
if (car.length) {
//register the function as asynchronous
process.nextTick(function() {
callback();
})
}
}
function logCars(cars) {
var car = cars.pop();
showCar(car, function() { //chaining of call backs
logCars(car);
});
}
var cars = ['ferrari', 'porsh', 'Hyundai', 'Peugeot'];
logCars(cars);