如果另一个代码片段已运行,我想运行代码。
如果此代码运行
(function() {
// Code runs here
})();
然后也运行此代码
//This code
示例
if (condition) {
block of code to be executed if the condition is true
}
http://www.w3schools.com/js/js_if_else.asp https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Statements/if...else
这似乎不起作用?
if ((function() {// Code runs here})();)
{
//This code
}
最佳答案
您应该使用 return 语句,否则 IIFE 将返回 undefined,因此它相当于 false 语句。
if (
(function() {
// Code runs here
return true;
})();
){
//This code
}
关于javascript - 如果此代码运行则执行代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37137367/