1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <title></title> 6 </head> 7 <body> 8 <script> 9 //函数也是一种数据类型 10 function fn() { 11 } 12 // funtion 数据类型 --> 对象(数组、函数) 13 //console.log( typeof fn); 14 15 function f1(s){ 16 var k = 123+s; 17 console.log(k); 18 } 19 f1('sss'); 20 21 var f2 = function(){ 22 console.log(222); 23 } 24 // f2 函数会被当做值,传入 f1 函数内 25 //回调 26 f1(f2); 27 </script> 28 </body> 29 </html>
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <title></title> 6 </head> 7 <body> 8 <script> 9 function f1(){ 10 var a=10; 11 var f2= function(){ 12 alert(2); 13 } 14 return f2; 15 } 16 //闭包 17 var k=f1(); 18 k(); 19 </script> 20 </body> 21 </html>标签:function,f1,f2,console,函数,当作,参数,var From: https://www.cnblogs.com/webaction/p/16655648.html