I defined an array variable in the function, which contains 6 elements, and then called the callback function in the function. The value of the array variable cannot be accessed in the callback function, but the length attribute can be accessed. I feel very confused and don't know how to solve it.
for(var i=0;i
Book.getBookByISBN() is a function I defined in other modules
Because
So
Put bookARR[i] in callback
The reason has been mentioned before. In fact, it is just to pass in bookArr[i] where you define the callback call in the Book.getBookByISBN() function. Understand the formal parameters and actual parameters
This is a typical asynchronous problem, and the scope of i is still within it.
Because I’m waiting for you asynchronously
getBookByISBN
方法调用callback的时候i=bookARR.length
。这已经越界了,所以是undefined
.Solution:
1. Closure
2.let