Skip to content

Instantly share code, notes, and snippets.

@davidsharp
Created August 17, 2021 13:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidsharp/b6df5369438f845035d28a5966378313 to your computer and use it in GitHub Desktop.
Save davidsharp/b6df5369438f845035d28a5966378313 to your computer and use it in GitHub Desktop.
Example of using JS proxies as a wrapper for localStorage
// localStorageProxy.foo = 'bar'
// -> localStorage.getItem('foo') = 'bar'
localStorageProxy = new Proxy(localStorage, {
get: (r,n)=>r.getItem(n),
set: (r,n,v)=>r.setItem(n,v),
deleteProperty: (r,n)=>r.removeItem(name)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment