I want to make a function that add an item to my localStorage object. E.g.:
alert(localStorage.getItem('names').addItem('Bill').getItem('names'));
The first method is getItem which gets the item for localStorage objects… but addItem would be a custom function. This chain of functions would finally alert Bill.
So, how would I make this function chain to localStorage?
This is possible if you create a wrapper/decorator object that makes chaining possible. This is how jQuery works for example. But it is useless in this case.
I made a possible implementation, though.
But getItem will break the chain (so it should always be used at the end).
Implementation