The problem of JS method call parentheses is discussed

  • 2020-03-30 01:25:11
  • OfStack

HTML page on mobile,

I wrote a function.
 
function showAlert(msg,fn){ 
showDialog("alert", msg," Warm prompt ",260); 
if(isNull(fn) == false){ 
$("#SD_confirm").unbind("click"); 
$("#SD_confirm").bind("click",fn); 
} 
} 

function exist(){ 

alert("aaa"); 

} 

Fn is a function that I wrote when I called it
 
showAlert(json.msg,exist()); 

It turns out that as soon as we get to this line of code, before we get to the showDialog method, we go to exist and it pops up aaa.

Should be written as
 
showAlert(json.msg,exist); 

This will prompt the dialog, and then click ok to bring up aaa.

Sister's. Originally is the wrong parenthesis. Sweat!

Related articles: