模拟实现一个 localStorage
作者:
TerdShow | 来源:发表于
2019-07-11 16:22 被阅读0次class localStorageMock {
constructor() {
this.store = {};
};
getItem(key) {
return this.store[key] || null;
};
setItem(key, value) {
this.store[key] = value.toString();
};
removeItem(key) {
delete this.store[key];
};
clear() {
this.store = {};
};
};
window.localStorage2 = new localStorageMock();
localStorage2.setItem('a', 1);
localStorage2.getItem('a');
console.log(localStorage2.getItem('a'));
本文标题:模拟实现一个 localStorage
本文链接:https://www.haomeiwen.com/subject/rtedkctx.html
网友评论