Skip to content

Instantly share code, notes, and snippets.

@petermichaux
Created February 19, 2012 20:43
Show Gist options
  • Save petermichaux/1865666 to your computer and use it in GitHub Desktop.
Save petermichaux/1865666 to your computer and use it in GitHub Desktop.
var seq = seq || (function () {
// Private vars
var sequences = {},
def_seq = 'unnamed',
instance;
// Methods implementation
return {
curVal: function(seq_name) {
seq_name = seq_name || def_seq;
if (typeof sequences[seq_name] === 'undefined') {
this.reset(seq_name);
}
return 'L_'+sequences[seq_name];
},
nextVal: function(seq_name) {
seq_name = seq_name || def_seq;
if (typeof sequences[seq_name] === 'undefined') {
this.reset(seq_name);
}
return 'L_' + (sequences[seq_name] += 1);
},
reset: function(seq_name) {
seq_name = seq_name || def_seq;
sequences[seq_name] = 0;
}
};
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment