Something like this? var prevA; function goThere(newA) { prevA = newA; this.pageNum = newA; } function goBack() { this.pageNum = prevA; } |
No. This is the first test I made.
In this case goBack will always go to the current page, since prevA is always equal to newA.
What I want to achieve:
User clic goThere(4) to go to page 4.
User clic goThere(6) to go to page 6.
User clic goThere(9) to go to page 9.
User clics goBack ==> he should go to page 6
I just need one goBack, not several.
(Don't ask me why, but I cannot use app.goBack() for this document.)
So it's not the previous value of A, it's the one before that...
You can do it like this:
var prevA = [];
function goThere(newA) {
prevA.push(newA);
this.pageNum = newA;
}
function goBack() {
if (prevA.length>=2) this.pageNum = prevA[prevA.length-2];
else console.println("can't go back.");
}