change local storage support check
This commit is contained in:
+18
-16
@@ -18,24 +18,26 @@ window.fakeStorage = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
function isLocalStorageNameSupported()
|
function LocalScoreManager() {
|
||||||
{
|
this.key = "bestScore";
|
||||||
var testKey = 'test', storage = window.localStorage;
|
|
||||||
try {
|
var supported = this.localStorageSupported();
|
||||||
storage.setItem(testKey, '1');
|
console.log(supported);
|
||||||
storage.removeItem(testKey);
|
this.storage = supported ? window.localStorage : window.fakeStorage;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
catch (error) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function LocalScoreManager() {
|
LocalScoreManager.prototype.localStorageSupported = function () {
|
||||||
var localSupported = isLocalStorageNameSupported();
|
var testKey = "test";
|
||||||
this.key = "bestScore";
|
var storage = window.localStorage;
|
||||||
this.storage = localSupported ? window.localStorage : window.fakeStorage;
|
|
||||||
}
|
try {
|
||||||
|
storage.setItem(testKey, "1");
|
||||||
|
storage.removeItem(testKey);
|
||||||
|
return true;
|
||||||
|
} catch (error) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
LocalScoreManager.prototype.get = function () {
|
LocalScoreManager.prototype.get = function () {
|
||||||
return this.storage.getItem(this.key) || 0;
|
return this.storage.getItem(this.key) || 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user