Skip to content

Instantly share code, notes, and snippets.

@crmckenzie
Created July 22, 2014 18:03
Show Gist options
  • Save crmckenzie/714748a4709d70200668 to your computer and use it in GitHub Desktop.
Save crmckenzie/714748a4709d70200668 to your computer and use it in GitHub Desktop.
FakeLocalStorage
define([], function() {
function FakeLocalStorage() {
var self = this;
self.length = 0;
self.keys = [];
return self;
}
FakeLocalStorage.prototype.key = function (i) {
var self = this;
return self.keys[i];
};
FakeLocalStorage.prototype.getItem = function (key) {
var self = this;
return self[key];
};
FakeLocalStorage.prototype.setItem = function (key, value) {
var self = this;
self[key] = value;
if (self.keys.indexOf(key) === -1) {
self.keys.push(key);
}
self.length = self.keys.length;
};
FakeLocalStorage.prototype.clear = function () {
var self = this;
for (var i = 0; i < self.keys.length; i++) {
var key = self.keys[i];
self[key] = undefined;
}
self.keys = [];
self.length = 0;
};
return FakeLocalStorage;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment