【发布时间】:2016-06-19 07:39:24
【问题描述】:
test.html
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src = "./test1.js"></script>
<script src = "./test2.js"></script>
</head>
</html>
test1.js
var a;
$(document).ready(function(){
setTimeout(function(){
a=10;
},1000);
});
test2.js
$(document).ready(function(){
//Busy waiting... doesn't Work.
/*while(typeof(a) === "undefined"){
console.log(a);
};*/
console.log(a);
});
test2 打印 'a' is 'undefined'... 如何在两个 javascript 文件上同步“a”?
【问题讨论】:
-
while(typeof(a) === "undefined"){ console.log(a); };从来都不是一个好主意。它会阻塞线程
标签: javascript jquery global-variables prototype synchronize