The difference between access to brackets and access to objects by objects is simply a convenience of the language. The difference between direct access to properties and using getter / setter methods is interesting.
The spectrum says:
"Supported property names in a Storage object are the keys of each key / value pair that are currently present in the list associated with the object.
This tells me that direct access is absolutely complete. those. all user agents implementing the specification must support it.
The better. I am not sure what the purpose of the specification is, so to speak. He cannot say how a particular user agent implementation can be biased towards one method or another due to its internal actions. The specification really just defines the interface.
For example, if direct access to properties in a specific user agent simply called getter / setting methods internally, then perhaps using these methods would benefit performance.
Personally, I would use methods, but rejected the functionality in my application to a simple function, which I can change if I need later. eg:
function getLocal( key ){ return localStorage.getItem(key); }
If for some reason I find a problem with this or need the support of old browsers (say, when returning to normal cookies), I can just change my application in one place. I know that this is not your question, but it is.
source share