单例模式
J-DuYa opened this issue · comments
flytree commented
-
概念讲解
-
原理解析
-
代码实现
# class 实现
class Storage {
static getInstance () {
if (!Storage.instance) {
Storage.instance = new Storage();
}
return Storage.instance;
}
getItem (key) {
return localstorage.getItem(key);
}
setItem (key, value) {
localstorage.setItem(key, value);
}
}