Skip to content

Incompatible property enumeration and toJSON method #2

@semmel

Description

@semmel

Unfortunately I rely on things like Object.keys(localStorage) to give me the keys of all items stored.

var isolated = new MemoryStorage('my-app');
isolated.setItem("test", JSON.stringify({ key: "value" }));
Object.keys(isolated);  
/// returns ["id", "length", "getItem", "setItem", "removeItem", "key", "clear", "test"]

localStorage.setItem("test", JSON.stringify({ key: "value" }));
Object.keys(localStorage); 
/// returns ["test"] 

It might be related, also that the output of applying JSON.stringify is not compatile to localStorage. It should be

JSON.stringify(localStorage)
// returns {"test":"{\"key\":\"value\"}"}

but instead it is

JSON.stringify(isolated)
// returns {"id":"my-app","length":1,"test":"{\"key\":\"value\"}"}

Perhaps one should define a .toJSON method to fix that behaviour.

With best regards
Semmel

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions