Replies: 1 comment
-
Custom LocalStorage를 만들면 좋은 점이
getItem(key) {
try {
return JSON.parse(localStorage.getItem(key));
} catch {
localStorage.removeItem(key);
alert(ERROR_MESSAGE.FAIL_TO_GET_DATA);
}
} JSON.parse는 string만 받을 수 있을 거임. 어떤 경우인지 잘 생각이 안나는데, 잘못 저장되면 load에 실패하게됨! 이 예외처리 코드를 함께 포함해줄 수 있음!! 그래서 지금 현재 코드의 단점은
LocalStorage.setItem('user', JSON.stringify(value)) 와 같은 형식으로 사용해야 하는데요. 이상한 점 있으면 또 달아주세요! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
From @joohaem
LocalStorage 에 메소드를 정의해 사용하여 짜는 코드에서 참고하면 좋을 말을 들어 공유합니다 !!
현재 LocalStorage 클래스
이러한 코드리뷰를 봐서, 메소드를 정의할 때 LocalStorage 내부가 아닌 이를 상속한 다른 class를 정의하는 게 어떨까 생각해봤어요!
Beta Was this translation helpful? Give feedback.
All reactions