关于《JS的数据结构与算法》中的迭代器始终会死循环?该怎么解决

关于《JS的数据结构与算法》中的迭代器始终会死循环?
最近在看JS的数据结构与算法,不才,才看到第三章还没结束,根据书上的例子自己敲了一遍,发现死循环,不知道什么原因,特来向大神们请教。代码如下:
function List(){
this.listSize = 0;
this.pos = 0;
this.dataStore = [];
this.clear = clear;
this.find = find;
this.toString = toString;
this.insert = insert;
this.append = append;
this.remove = remove;
this.front = front;
this.end = end;
this.prev = prev;
this.next = next;
this.length = length;
this.currPos = currPos;
this.moveTo = moveTo;
this.getElement = getElement;
this.contains = contains;
}

function append(element){
this.dataStore[this.listSize++] = element;
}

function find(element){
for(var i = 0; i < this.dataStore.length; i++){
if(this.dataStore[i] == element){
return i;
}
}
return -1;
}

function remove(element){
var foundAt = this.find(element);
if(foundAt > -1){
this.dataStore.splice(foundAt,1);
--this.listSize;
return true
}
return false;
}

function length(){
return this.listSize;
}

function toString(){
return this.dataStore;
}

function insert(element,after){
var insertPos = this.find(after);
if(insertPos > -1){
this.dataStore.splice(insertPos+1,0,element);
++this.listSize;
return true;
}
return false;
}

function clear(){
delete this.dataStroe;
this.dataStore = [];
this.listSize = this.pos = 0;
}

function contains(element){
for(var i = 0; i < this.dataStore.length; i++){
if(this.dataStore[i] == element){
return true;
}
}
return false;
}

function front(){
this.pos = 0;
}

function end(){
this.pos = this.listSize-1;
}

function prev(){
if(this.pos > 0){
--this.pos;
}
}

function next(){
if(this.pos < this.listSize-1){
++this.pos;
}
}

function currPos(){
return this.pos;
}

function moveTo(position){
this.pos = position;
}

function getElement(){
return this.dataStore[this.pos];
}

var movies = [ "The Shawshank Redemption",
"The Godfather",
"The Godfather: Part II",
"Pulp Fiction",
"The Good, the Bad and the Ugly",
"12 Angry Men",
"Schindler’s List",
"The Dark Knight",
"The Lord of the Rings: The Return of the King",
"Fight Club",
"Star Wars: Episode V - The Empire Strikes Back",
"One Flew Over the Cuckoo’s Nest",
"The Lord of the Rings: The Fellowship of the Ring",
"Inception",
"Goodfellas",
"Star Wars",
"Seven Samurai",
"The Matrix",
"Forrest Gump",
"City of God" ];

var movieList = new List();
for(var i = 0; i<movies.length; i++){
movieList.append(movies[i]);
}

function Customer(name,movie){
this.name = name;
this.movie = movie;
}

function displayList1(list){
for(list.front(); list.currPos()<list.length(); list.next()){
document.write(list.getElement()+"<br>");
}
}

function displayList(list){
for(list.front(); list.currPos()<list.length(); list.next()){
if(list.getElement() instanceof Customer){
document.writeln(list.getElement()["name"] + "," + list.getElement()["movie"]);
}else{
document.writeln(list.getElement());
}
}
}

function checkOut(name,movie,filmList,customerList){
if(movieList.contains(movie)){
var c = new Customer(name,movie);
customerList.append(c);
filmList.remove(movie);
}else{
document.write(movie + "is not available");
}
}

var customers = new List();

document.write("Available movies: \n");
displayList1(movieList);//为什么始终死循环?不解

------解决思路----------------------
原因是list中的next方法出现了问题:
function next(){
    if(this.pos < this.listSize-1){
        ++this.pos;
    }
}
应该改成:
function next(){
    if(this.pos < this.listSize){
        ++this.pos;
    }
}