Store best score in localStorage
Dependency injection and hide best score for incompatible browsers
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
function LocalScoreManager() {
|
||||
this.key = 'bestScore';
|
||||
}
|
||||
|
||||
LocalScoreManager.prototype.get = function () {
|
||||
if (!this.isSupported()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return localStorage.getItem(this.key);
|
||||
};
|
||||
|
||||
LocalScoreManager.prototype.set = function (score) {
|
||||
if (!this.isSupported()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
localStorage.setItem(this.key, score);
|
||||
};
|
||||
|
||||
LocalScoreManager.prototype.isSupported = function () {
|
||||
return !!window.localStorage;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user