Save Javascript objects in sessionStorage

后端 未结 9 707
抹茶落季
抹茶落季 2020-12-02 05:14

SessionStorage and LocalStorage allows to save key/value pairs in a web browser. The value must be a string, and save js objects is not trivial.

var user = {         


        
9条回答
  •  抹茶落季
    2020-12-02 05:18

    Either you can use the accessors provided by the Web Storage API or you could write a wrapper/adapter. From your stated issue with defineGetter/defineSetter is sounds like writing a wrapper/adapter is too much work for you.

    I honestly don't know what to tell you. Maybe you could reevaluate your opinion of what is a "ridiculous limitation". The Web Storage API is just what it's supposed to be, a key/value store.

提交回复
热议问题