JavaScript中函数带与不带括号的区别
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <script type="text/javascript"> function f() { alert('我是f函数'); return 1; } var v1 = f(); //将函数f()的返回值赋值给v1 alert(v1); var v2 = f; //将函数体赋值给v2 v2(); </script> </head> <body> </body> </html>