提交 2bf48efe 编写于 作者: G Gabriele Cirulli

change local storage support check

上级 15057fd6
...@@ -18,24 +18,26 @@ window.fakeStorage = { ...@@ -18,24 +18,26 @@ window.fakeStorage = {
} }
}; };
function isLocalStorageNameSupported() function LocalScoreManager() {
{ this.key = "bestScore";
var testKey = 'test', storage = window.localStorage;
var supported = this.localStorageSupported();
console.log(supported);
this.storage = supported ? window.localStorage : window.fakeStorage;
}
LocalScoreManager.prototype.localStorageSupported = function () {
var testKey = "test";
var storage = window.localStorage;
try { try {
storage.setItem(testKey, '1'); storage.setItem(testKey, "1");
storage.removeItem(testKey); storage.removeItem(testKey);
return true; return true;
} } catch (error) {
catch (error) {
return false; return false;
} }
} };
function LocalScoreManager() {
var localSupported = isLocalStorageNameSupported();
this.key = "bestScore";
this.storage = localSupported ? window.localStorage : window.fakeStorage;
}
LocalScoreManager.prototype.get = function () { LocalScoreManager.prototype.get = function () {
return this.storage.getItem(this.key) || 0; return this.storage.getItem(this.key) || 0;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册