从localStorage中删除:我应该使用delete还是.removeItem? [英] Deleting from localStorage: should I use delete or .removeItem?

查看:1374
本文介绍了从localStorage中删除:我应该使用delete还是.removeItem?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Chrome扩展程序中使用了 localStorage

I'm using localStorage in a Chrome extension.

删除localStorage [key] window.localStorage.removeItem(key)或者它们的行为是否相同?

Is there any difference between delete localStorage[key] and window.localStorage.removeItem(key) or do they behave identically?

请注意,我选择 window.localStorage.removeItem(key)来完全对应 spec ,但是 localStorage.removeItem(key)看看在野外。

Note that I choose window.localStorage.removeItem(key) to correspond exactly to the spec, but localStorage.removeItem(key) is how it would probably look in the wild.

推荐答案

在Chrome中没有区别,但我推荐使用localStorage.removeItem(key)习惯于这样做。这样,当您在网站中使用localStorage时,您已经在使用最有可能用于填充和填充过时浏览器的方法。

There's no difference in Chrome, but i recommend using localStorage.removeItem(key) so that you get in the habit of doing so. That way, when you go to use localStorage in a website, you are already using the method that is most likely to work with shims and polyfills for outdated browsers.

这篇关于从localStorage中删除:我应该使用delete还是.removeItem?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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