<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script type=text/javascript charset=utf-8> function F(){ alert("函数F") var a= 1; return function(){ this.name = a++; alert(this.name); } } var f1 = F();// 函数F f1();//1 f1();//2 var f2 = F();// 函数F f2();//1 f2();//2 var f3 = F();// 函数F var f31 = new f3();//1 alert(f31.name);//1 var f32 = new f3();//2 alert(f32.name);//2 //------------------------------------------------ var f4 = new F();// 函数F f4();//1 f4();//2 var f5 = new F();// 函数F f5();//1 f5();//2 var f6 = new F();//函数F var f61 = new f6();//1 alert(f61.name);//1 var f62 = new f6();//2 alert(f62.name);//2 </script> </head> <body> </body> </html>
外层函数既可以当成函数看也可以当成类看。内部返回的既可以当成函数看也可以当成类看。
时间: 2024-10-05 20:25:23