这用于使用 Chrome 扩展程序的 JavaScript 访问保存在 chrome.storage.sync 中的首选项。
代码:
chrome.storage.sync.get('allWeights', function(obj) {
allWeights = obj.allWeights();
chrome.storage.sync.get('allIDs', function(obj2) {
allIDs = obj2.allIDs();
alert("ALL WEIGHTS: " + allWeights);
alert("ALL IDS: " + allIDs);
});
});
错误:
Error in response to storage.get: TypeError: object is not a function at HTMLDocument.restore_options
错误指向第一行(chrome.storage.sync.get('allWeights')。
是什么原因导致此错误以及如何修复它?
最佳答案
编辑:这有效
chrome.storage.sync.get(null, function(items) {
allWeights = items.allWeights;
allIDs = items.allIDs;
alert("ALL WEIGHTS: " + allWeights);
alert("ALL IDS: " + allIDs);
});
我必须将 items.allWeights() 更改为 items.allWeights。
显然你不能使用 () 访问对象属性
关于javascript - 类型错误 : Object Is Not A Function (JavaScript Chrome Storage Sync),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26619522/