I want to call a function with an argument and store the value so that next time I call that function without arguments it uses the last argument that was set. Is this possible with JavaScript?
Edit: Here's more info on what I'm trying to achieve...
var track = 0;
$.getJSON('songsMetadata.json', function(data){
appendData(data);
});
player.bind("ended", function(){
track++
appendData();
});
function appendData(data){
/* Here I want to populate
the inside 'data' argument
only once (in the callback of
getJSON) and use that same
data in the 'player.bind'
callback */
//Some code to append data[track] to an HTML list
}
appendDatain the wrapper function.var cachedAppend = cacheFn(appendData);then usecacheAppendin all places you would useappendData. This normalizesappendDataso it always gets called with some argument, either the one being passed, or the last argument to have been passed (as you specified in your question).