I have the below code,
it is running however the output in the consol开发者_如何学编程e is
instant: true
instant2: false
as the variable is not being overwritten in the global scope. How can I access the variable in the global scope?
var instant = false;
$('document').ready(function(){
chrome.extension.sendRequest({
action: "getStorage",
key: "instant"
}, function(response) {
instant = true;
console.log('instant: ', instant);
});
console.log('instant2: ', instant);
});
It is getting overridden, but later. Your function(response)
isn't getting executed until after the outer function returns.
window.instant
should get you the value of your global variable.
精彩评论