gpt4 book ai didi

javascript - 如果取消对 localStorage 的写入会发生什么?

转载 作者:太空狗 更新时间:2023-10-29 15:55:36 25 4
gpt4 key购买 nike

假设我像这样调用本地存储:

window.localStorage.setItem("key", bigJsonObject);

紧接着,用户关闭了他们的网络浏览器。结果会怎样

window.localStorage.getItem("key") 

bigJsonObject 会被部分写入吗?或者整个写入会失败吗?他们有什么方法可以保证不会出现部分写入吗?

最佳答案

引用§4.1 of the "web storage" specification :

The setItem() and removeItem() methods must be atomic with respect to failure. In the case of failure, the method does nothing. That is, changes to the data storage area must either be successful, or the data storage area must not be changed at all.

但是,(历史上)在这方面存在浏览器错误,e.g. some time before Chrome 21 until some time before Chrome 29 .

关于javascript - 如果取消对 localStorage 的写入会发生什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27806095/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com