Which is the better option to use: localStorage(),

2019-03-12 16:20发布

问题:

The question says it all. I realize that all options do work in up-to-date browsers, but what is the semantically best choice, and why?

回答1:

Good question. According to W3C standards, the correct is window.localStorage because the localStorage attribute is part of window object. And it is not a function, it is an attribute.

Source: http://dev.w3.org/html5/webstorage/#dom-localstorage Example: http://www.rajdeepd.com/articles/chrome/localstrg/LocalStorageSample.htm