我有下面的代码,
它正在运行,但是控制台中的输出是
瞬间:真
instant2:假
因为变量没有在全局范围中被覆盖。如何访问全局范围中的变量?
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);
});发布于 2010-11-16 09:21:42
它正在被覆盖,但稍后会被覆盖。直到外部函数返回之后,function(response)才会被执行。
发布于 2010-11-16 09:24:34
window.instant应该为您获得全局变量的值。
https://stackoverflow.com/questions/4192597
复制相似问题