哪个是更好的选择:localStorage(),window.localStorage()或document.localStorage()? [英] Which is the better option to use: localStorage(), window.localStorage(), or document.localStorage()?

查看:104
本文介绍了哪个是更好的选择:localStorage(),window.localStorage()或document.localStorage()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题说明了一切。我意识到所有选项都可以在最新的浏览器中运行,但是什么是语义上最好的选择,为什么?

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?

推荐答案

好问题。根据W3C标准,正确的是window.localStorage,因为localStorage属性是window对象的一部分。它不是一个函数,它是一个属性。

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.

来源: http://dev.w3.org/html5/webstorage/#dom-localstorage
示例: http://www.rajdeepd.com/articles/chrome/localstrg/LocalStorageSample.htm

这篇关于哪个是更好的选择:localStorage(),window.localStorage()或document.localStorage()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆