class BrowserHistory {
/**
* @param {string} url
* if url is set, it means new tab with url
* otherwise, it is empty new tab
*/
constructor(url) {
this.queue=[]
//当前current位置
this.currentIndex=0
if(url !== undefined){
this.queue.push(url)
}
}
/**
* @param { string } url
*/
visit(url) {
//截断currentIndex后面的记录
this.queue.length = this.currentIndex+1
this.queue.push(url)
this.currentIndex += 1
}
/**
* @return {string} current url
*/
get current() {
return this.queue[this.currentIndex]
}
// go to previous entry
goBack() {
this.currentIndex=Math.max(0,this.currentIndex-1)
}
// go to next visited url
forward() {
this.currentIndex=Math.min(this.queue.length-1,this.currentIndex+1)
}
}