1
function getBugVal() {
var bugVal = "";
chrome.storage.sync.get('bugId', function (obj) {
console.log(obj.bugId);
bugVal = obj.bugId;
console.log(bugVal + "<- val inside get sync");
});
console.log(bugVal + "<- val outside get sync");
return bugVal;
}
如果我叫getBugVal()的返回值保持指示空字符串而不是從chrome.storage.sync.get實際值。 bugVal甚至沒有保存字符串值。Chrome.storage.sync.get不是在局部變量存儲值
console.log(bugVal + "<- val inside get sync");
在內部函數調用中產生正確的值。思考?