chrome.storage.local 存储时更改对象

我正在尝试进行扩展,我想知道是否有任何方法可以避免我遇到的这个问题? 当我使用 chrome 存储 api 存储一个扩展另一个对象的对象时,它会在存储时更改数组中对象的 [[Prototype]]。我尝试了以下代码通过设置值然后在回调中获取它来重复问题,这就是我得到的。这是 chrome API 正在做的事情,还是我误解了 javascript 中对象的概念?

class Baseclass{
    constructor(){
    }
    testFunc(){
        console.log("Base Class testFunc")
    }
}

class SubClass extends Baseclass{
    constructor(){
        super();
    }
    testFunc(){
        super.testFunc();
        console.log("Sub Class testFunc")
    }
}

var testArr = [new SubClass()];
console.log(testArr);

chrome.storage.local.set({"test":testArr},()=>{
    chrome.storage.local.get("test",(result)=>{
        console.log(result.test);
    })
})

chrome.storage.local 存储时更改对象

任何帮助将不胜感激。

cxd345 回答:chrome.storage.local 存储时更改对象

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3870.html

大家都在问