Created
May 20, 2015 04:28
-
-
Save krizpoon/9b451a456b0df7cb604d to your computer and use it in GitHub Desktop.
A history list object that behaves like browser's history
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function HistoryList(home) | |
{ | |
var arr = [home]; | |
var ptr = 1; | |
this.push = function(elem) { arr.splice(ptr, arr.length-ptr, elem); ptr = arr.length; return this; } | |
this.moveTo = function(pos) { ptr = Math.min(Math.max(1, pos), arr.length); return this; } | |
this.move = function(steps) { return this.moveTo(ptr + steps); } | |
this.get = function() { return arr[ptr-1]; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment