Created
August 17, 2021 13:08
-
-
Save davidsharp/b6df5369438f845035d28a5966378313 to your computer and use it in GitHub Desktop.
Example of using JS proxies as a wrapper for localStorage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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