Advertisement
Guest User

Untitled

a guest
Feb 10th, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. function getStore() {
  2. function getStore() {
  3. return new Proxy({}, {
  4. set: (target, property, value) => localStorage.setItem(property, JSON.stringify(value)),
  5. get: (target, property) => JSON.parse(localStorage.getItem(property))
  6. });
  7. }
  8. }
  9.  
  10. let store = getStore();
  11.  
  12. // Aquí se hace uso del nuevo setter
  13. store.user = {
  14. name: 'José Antonio',
  15. pass: 'casa'
  16. };
  17.  
  18. // Aquí se hace uso del nuevo getter
  19. console.log(store.user);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement