Hello I am wondering how to write a proper wrapper for something like sessionStorage
.
I could implement a class of my own and proxy through method invocation to the sessionStorage
. For example with some quick pseudocode:
class customStorage {
set(key, value) {
sessionStorage.setItem(key, value);
}
}
I would use it like so:
const customStorage = new customStorage();
customStorage.set('my-key', 'hello there');
All fine and dandy but I would like for a user to have the freedom to use other native sessionStorage
methods on my proxy that I might not implement myself in my proxy.
for something like sessionStorage
it would be do-able to write them all yourself even though all they might do is proxy through to sessionStorage
without any intervention.
For something larger where I would only manipulate 5 methods out of 20 or something this does not seem viable.
Overwriting native functionality with prototype also seems like a deathtrap leading to many wtfs-per-minute
.
So far what I have read from 'proxy patterns' in Javascript they all implemented all of the methods from the original Object. Am I forced to do this?
Is there some sort of way to create an ES6 class and set the prototype of that very class to sessionStorage in the constructor or something?