$(function () {
let check = function() {
setTimeout(function () {
if (cLANGUAGE == null)
check();
}, 500);
};
if (cLANGUAGE == null) check();
alert(cLANGUAGE);
$('#details--action-share').on('click', function () {
Action.details.share.before();
});
});
Run Code Online (Sandbox Code Playgroud)
当我这样写时,它仍然警告 cLanguage 为空。我想等到 cLanguage 不为空然后运行下面的代码
$('#details--action-share').on('click', function () {
Action.details.share.before();
});).
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
将所有依赖于它不为空的代码放在一个else块中,以防=== null计算结果为false:
let check = function() {
setTimeout(function () {
if (cLANGUAGE === null)
check();
else {
alert(cLANGUGAGE);
}
}, 500);
};
check();
Run Code Online (Sandbox Code Playgroud)