I am currently develoing a webapp where I have to worry about potentially large arrays. Those arrays contain a number of ids, that will be added to html-lists. So given an array of 170 ids I will end up with a ul, that holds 170 li-elements. Since I don't have to worry about search, but performance I decided to use lazy loading. So far I am loading the big array once and am now writing a function, that adds new element according to the users position.
This function needs to remember its last position, in case it does not get a specific new number (the second parameter beeing set). I tried to realize this with the help of a function attribute. Here is what I have so far (ids being the array, pos the position which can be set):
Player.prototype.showPlaylist = function (ids, pos) {
//In case pos isn't set, use your old value
showPlaylist.pos = pos !== "undefined" ? showPlaylist.pos : showPlaylist.pos;
console.log(showPlaylist.pos);
for (var i = showPlaylist.pos; i < ids.length; i++) {
//create new html elements
}
}
Unfortunately I get a
showPlaylist is not defined
at the console.log(). This is the first time I am working with both lazy loading and a function which has a memory, so there might be a better solution (I really what to avoid global variables though).